电话处于睡眠模式时,WearableListenerService / Android中的连接被拒绝

时间:2015-03-16 21:30:30

标签: android wear-os

我正在开发一个Android Wear Watchface,通过向我的移动应用程序发送MessageAPI请求来访问Internet,我正在运行WearableListenerService,在我的移动应用程序中,我收到来自onMessageReceived的请求,并且onMessageReceived我启动一个AsyncTask来从Internet检索图像。

通常

但是,如果手机处于非活动状态几分钟(屏幕黑色,未通过USB连接到我的Mac),当AsyncTask尝试检索此行上的输入流时,我收到“ECONNREFUSED - 服务器拒绝连接”:

InputStream is = (InputStream) new URL(mUrl).getContent();

以下是例外:

java.net.ConnectException: failed to connect to dl.dropboxusercontent.com/xx.xx.xxx.xx (port 443): connect failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.connect(IoBridge.java:118)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)
at java.net.Socket.connect(Socket.java:838)
at com.android.okhttp.internal.Platform.connectSocket(Platform.java:131)
at com.android.okhttp.Connection.connect(Connection.java:101)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getHeaderField(HttpURLConnectionImpl.java:143)
at java.net.URLConnection.getContentType(URLConnection.java:326)
at java.net.URLConnection.getContent(URLConnection.java:193)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getContent(HttpsURLConnectionImpl.java:169)
at java.net.URL.getContent(URL.java:455)
at wear.webcam.MobileRequestListenerService$MyImageLoaderTask.doInBackground(MobileRequestListenerService.java:479)
at wear.webcam.MobileRequestListenerService$MyImageLoaderTask.doInBackground(MobileRequestListenerService.java:451)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
at libcore.io.Posix.connect(Native Method)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
at libcore.io.IoBridge.connectErrno(IoBridge.java:131)
at libcore.io.IoBridge.connect(IoBridge.java:116)
... 23 more
  • 我的应用程序在一分钟后重试,当手机开启(屏幕开启)时,它可以正常工作!
  • 它与我正在调用的服务器/网址无关,因为我在不同服务器上遇到同样的错误。
  • 它与Wifi无关,因为无论是在Wifi还是普通网络中都会发生这种情况。
  • 这发生在PROD / Signed和DEBUG版本
  • 我正在检查网络是否在通话之前可用,并且我回到“真实”,所以网络确实开启了!

public boolean isNetworkAvailable() {
    ConnectivityManager cm = (ConnectivityManager)
            getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    // if no network is available networkInfo will be null
    // otherwise check if we are connected
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    }
    return false;
}

看起来这个问题可以通过获取唤醒锁来解决 - 但到目前为止这还没有解决问题。

任何帮助表示赞赏!!!

Android 4.4.4索尼Xperia Z1; Android Wear 5.0.2。

1 个答案:

答案 0 :(得分:0)

解决:事实证明,原因是Xperia上的节能选项:它被设置为" STAMINA-Modus",这导致设备无法唤醒。