Android穿2个wifi局域网接入
Android Wear 2 WiFi local network access
我通过改造进行了一些 REST 调用,访问我本地 WiFi 网络上的本地 IP 地址,在移动端工作得很好,但是一旦在独立的磨损应用程序上我有这个错误:
java.net.SocketTimeoutException: connect timed out
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.PlainSocketImpl.socketConnect(Native Method)
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.Socket.connect(Socket.java:605)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:63)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:223)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:149)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:195)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:211)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at com.mylisabox.network.interceptors.HostSelectionInterceptor.intercept(HostSelectionInterceptor.kt:33)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at com.mylisabox.network.interceptors.TokenInterceptor.intercept(TokenInterceptor.kt:25)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.RealCall.execute(RealCall.java:69)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:41)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Observable.subscribe(Observable.java:10903)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Observable.subscribe(Observable.java:10903)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Single.subscribe(Single.java:2700)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at hu.akarnokd.rxjava2.debug.SingleOnAssembly.subscribeActual(SingleOnAssembly.java:41)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Single.subscribe(Single.java:2700)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.lang.Thread.run(Thread.java:761)
如果我用在线 IP 地址替换本地 IP 地址,它在手表上也能正常工作。在移动应用程序上没问题,我可以正确访问相同的 URL 本地或远程。两个设备都在同一个 WiFi 网络下。
有什么想法吗?
当佩戴与手机连接然后使用移动互联网时,在这种情况下 API 代码无效。请断开佩戴与手机的连接,然后重试它会给您回复。
请看这个 link 我认为它对你有帮助:https://www.sitepoint.com/connecting-to-web-services-with-android-wear/
这个问题也一直困扰着我。情况似乎是,当 Android Wear 通过蓝牙连接到互联网(因此 phone)时,http/web 调用以某种方式被代理。
一个解决方案是禁用 phone 的蓝牙连接,这会强制 Android Wear 设备直接连接到本地 wifi(如果它首先支持 wifi),然后本地 API 请求神奇地开始工作。
一个更合适的解决方法(因为你不能真的要求你的用户每次使用你的应用程序时都断开与他们的 phone 的蓝牙连接),似乎是使用 NodeApi
检查生成的 phone 节点是否在附近(使用 Node.isNearby()
),如果是,则使用 MessageClient 将 API 请求代理到您自己的 phone,然后进行在 phone 上请求并最终回复结果。相当麻烦,但对我来说,这是调用本地 APIs...
的唯一可靠方法
如果有人知道为什么 Google 通过蓝牙代理这些呼叫或有其他解决此问题的建议,我也很想知道。
Wear将使用共享蓝牙连接,活动接口类型为PROXY而非WIFI。你可以通过adb shell dumpsys netstats
查看。在这种情况下,wear 与服务器不在同一个本地网络中,并且到服务器的套接字将超时。
一种解决方案是让您的服务器具有 public IP 或主机名。另一个是在访问 API 之前使用 NetworkRequest 更改与 wifi 的连接。请查看 google 的样本:https://github.com/googlesamples/android-WearHighBandwidthNetworking
我通过改造进行了一些 REST 调用,访问我本地 WiFi 网络上的本地 IP 地址,在移动端工作得很好,但是一旦在独立的磨损应用程序上我有这个错误:
java.net.SocketTimeoutException: connect timed out
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.PlainSocketImpl.socketConnect(Native Method)
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
10-08 14:50:00.154 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.net.Socket.connect(Socket.java:605)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:63)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:223)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:149)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:195)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:211)
10-08 14:50:00.155 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at com.mylisabox.network.interceptors.HostSelectionInterceptor.intercept(HostSelectionInterceptor.kt:33)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at com.mylisabox.network.interceptors.TokenInterceptor.intercept(TokenInterceptor.kt:25)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at okhttp3.RealCall.execute(RealCall.java:69)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:41)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Observable.subscribe(Observable.java:10903)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Observable.subscribe(Observable.java:10903)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Single.subscribe(Single.java:2700)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at hu.akarnokd.rxjava2.debug.SingleOnAssembly.subscribeActual(SingleOnAssembly.java:41)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Single.subscribe(Single.java:2700)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
10-08 14:50:00.156 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
10-08 14:50:00.157 1804-1804/com.mylisabox.lisa E/HomeViewModel$onRefresh: at java.lang.Thread.run(Thread.java:761)
如果我用在线 IP 地址替换本地 IP 地址,它在手表上也能正常工作。在移动应用程序上没问题,我可以正确访问相同的 URL 本地或远程。两个设备都在同一个 WiFi 网络下。 有什么想法吗?
当佩戴与手机连接然后使用移动互联网时,在这种情况下 API 代码无效。请断开佩戴与手机的连接,然后重试它会给您回复。 请看这个 link 我认为它对你有帮助:https://www.sitepoint.com/connecting-to-web-services-with-android-wear/
这个问题也一直困扰着我。情况似乎是,当 Android Wear 通过蓝牙连接到互联网(因此 phone)时,http/web 调用以某种方式被代理。
一个解决方案是禁用 phone 的蓝牙连接,这会强制 Android Wear 设备直接连接到本地 wifi(如果它首先支持 wifi),然后本地 API 请求神奇地开始工作。
一个更合适的解决方法(因为你不能真的要求你的用户每次使用你的应用程序时都断开与他们的 phone 的蓝牙连接),似乎是使用 NodeApi
检查生成的 phone 节点是否在附近(使用 Node.isNearby()
),如果是,则使用 MessageClient 将 API 请求代理到您自己的 phone,然后进行在 phone 上请求并最终回复结果。相当麻烦,但对我来说,这是调用本地 APIs...
如果有人知道为什么 Google 通过蓝牙代理这些呼叫或有其他解决此问题的建议,我也很想知道。
Wear将使用共享蓝牙连接,活动接口类型为PROXY而非WIFI。你可以通过adb shell dumpsys netstats
查看。在这种情况下,wear 与服务器不在同一个本地网络中,并且到服务器的套接字将超时。
一种解决方案是让您的服务器具有 public IP 或主机名。另一个是在访问 API 之前使用 NetworkRequest 更改与 wifi 的连接。请查看 google 的样本:https://github.com/googlesamples/android-WearHighBandwidthNetworking