无法在wearos蓝牙上发送HTTP请求

问题描述 投票:1回答:1

我开发了一个os 2.0+应用程序,它与HTTP API进行通信。我正在使用Volley连接到这个API,但只有在我关闭蓝牙时它似乎才有效。我用蓝牙做的任何请求都会暂停。另一端通常在几毫秒内响应并返回不超过几千字节。

文档说明了有关网络访问的以下内容:

磨损OS应用程序可以发出网络请求。当手表与手机具有蓝牙连接时,手表的网络流量通常通过手机进行代理。但是当手机不可用时,将使用Wi-Fi和蜂窝网络,具体取决于硬件。 Wear平台处理网络之间的转换。

因此,根据我的理解,Android应该注意确保我的请求能够通过蓝牙(通过电话代理)或wifi来实现。

使用齐射发出HTTP请求的实际代码:

public <T> CompletableFuture<T> send(String url, Class<T> type) {
    CompletableFuture<T> requestCompletableFuture = new CompletableFuture<>();

    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            response -> {
                T data = serializer.fromJson(response.toString(), type);

                requestCompletableFuture.complete(data);
            }, (ex) -> {
                requestCompletableFuture.completeExceptionally(ex);
    });

    request.setRetryPolicy(new DefaultRetryPolicy(15000,
            0,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    requestQueue.add(request);

    return requestCompletableFuture;
}

Android确实提供了ConnectivityManager,使我能够请求WIFI网络。但创建一个我不需要的高带宽网络听起来有点不必要,电池正在耗尽我想要阻止的东西。

android wear-os
1个回答
1
投票

事实证明问题出在另一边。 API每次发送请求时都不会发送导致超时的响应。

如果您遇到类似问题,我建议您在蓝牙上进行测试。

© www.soinside.com 2019 - 2024. All rights reserved.