2

设备喜欢

  1. 三星 GalaxyTAB2 GT-P5113 安卓操作系统 4.1.1
  2. 联想安卓手机

在许多设备中,我的 InternetReachability 代码都可以使用

但上面的设备没有工作

       Toste Message  "Not Connect to the Internet"

互联网可达性代码

public boolean currentStatus(Context context)
    {

        try
        {
            if (context==null)
                return false;

            ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            return ( connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting() || connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting() );

        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            return false;
        }
    } 

当我可以在没有互联网 InternetReachability 代码的情况下从亚马逊下载产品时

错误会像这样发生

05-01 13:26:36.154: I/System.out(16813): THREAD IS ALIVE.
05-01 13:26:36.404: E/SpannableStringBuilder(16813): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-01 13:26:36.404: E/SpannableStringBuilder(16813): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-01 13:05:13.589: I/System.out(15658): THREAD IS ALIVE.
05-01 13:05:15.425: I/System.out(15658): ERROR in run() ----> : Status Code: 403, AWS Service: Amazon S3, AWS Request ID: 6D55BDA68E575EC9, AWS Error Code: RequestTimeTooSkewed, AWS Error Message: The difference between the request time and the current time is too large., S3 Extended Request ID: 8mfkdgLLXu2Zt1dsAkBdwAw7Qd2Ha4Ngyazg807u504/ZGbnS1tWNilV8kVUaknW
05-01 13:05:15.425: W/System.err(15658): Status Code: 403, AWS Service: Amazon S3, AWS Request ID: 6D55BDA68E575EC9, AWS Error Code: RequestTimeTooSkewed, AWS Error Message: The difference between the request time and the current time is too large., S3 Extended Request ID: 8mfkdgLLXu2Zt1dsAkBdwAw7Qd2Ha4Ngyazg807u504/ZGbnS1tWNilV8kVUaknW
05-01 13:05:15.433: W/System.err(15658):    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:583)
05-01 13:05:15.433: W/System.err(15658):    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:317)
05-01 13:05:15.433: W/System.err(15658):    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:167)
05-01 13:05:15.433: W/System.err(15658):    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2781)
05-01 13:05:15.433: W/System.err(15658):    at com.amazonaws.services.s3.AmazonS3Client.getObject(AmazonS3Client.java:872)
05-01 13:05:15.433: W/System.err(15658):    at org.Infoware.fb.DownloadThread.run(DownloadThread.java:113)
05-01 13:05:19.199: I/AmazonHttpClient(15658): Unable to execute HTTP request: No peer certificate
05-01 13:05:19.199: I/AmazonHttpClient(15658): javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.harmony.xnet.provider.jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:137)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:285)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:167)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2781)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at com.amazonaws.services.s3.AmazonS3Client.getObject(AmazonS3Client.java:872)
05-01 13:05:19.199: I/AmazonHttpClient(15658):  at org.Infoware.fb.DownloadThread.run(DownloadThread.java:113)
05-01 13:05:19.199: I/System.out(15658): ERROR in run() ----> : com.amazonaws.AmazonClientException: Unable to execute HTTP request: No peer certificate
05-01 13:05:19.199: W/System.err(15658): com.amazonaws.AmazonClientException: Unable to execute HTTP request: No peer certificate
05-01 13:05:19.199: W/System.err(15658):    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:332)
05-01 13:05:19.199: W/System.err(15658):    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:167)
05-01 13:05:19.207: W/System.err(15658):    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2781)
05-01 13:05:19.207: W/System.err(15658):    at com.amazonaws.services.s3.AmazonS3Client.getObject(AmazonS3Client.java:872)
05-01 13:05:19.207: W/System.err(15658):    at org.Infoware.fb.DownloadThread.run(DownloadThread.java:113)
05-01 13:05:19.207: W/System.err(15658): Caused by: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
05-01 13:05:19.207: W/System.err(15658):    at org.apache.harmony.xnet.provider.jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:137)
05-01 13:05:19.207: W/System.err(15658):    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
05-01 13:05:19.207: W/System.err(15658):    at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
05-01 13:05:19.207: W/System.err(15658):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
05-01 13:05:19.207: W/System.err(15658):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-01 13:05:19.207: W/System.err(15658):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-01 13:05:19.207: W/System.err(15658):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
05-01 13:05:19.207: W/System.err(15658):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-01 13:05:19.207: W/System.err(15658):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-01 13:05:19.207: W/System.err(15658):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-01 13:05:19.207: W/System.err(15658):    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:285)
05-01 13:05:19.207: W/System.err(15658):    ... 4 more

所以我必须做什么....我的 InternetReachability 代码和下载代码在所有设备上都能正常工作但上述设备无法正常工作......所以请帮助我

4

2 回答 2

1

错误代码表示您设备上的时钟有偏差。您检查系统时钟是否正确?

于 2013-04-30T21:58:10.197 回答
0

我建议你我也有同样的问题。你得到了关于这行代码的空指针异常。

connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting() 

它的响应为空。它仅在某些精选设备中提供。所以我建议你不要使用这个代码。

/**
       * Checks if the device has Internet connection.
       * 
       * @return <code>true</code> if the phone is connected to the Internet.
       */
      public static boolean hasConnection(Context context)
      {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        //This for Wifi.
        NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiNetwork != null && wifiNetwork.isConnected()) 
        {
          return true;
        }

        //This for Mobile Network.
        NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (mobileNetwork != null && mobileNetwork.isConnected()) 
        {
          return true;
        }

        //This for Return true else false for Current status.
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (activeNetwork != null && activeNetwork.isConnected()) 
        {
          return true;
        }
        return false;
      }

它对我有用,所以我希望它也对你有用。

祝你好运

于 2013-05-01T04:48:42.007 回答