【问题标题】:Nearby connection API for Android - not working for some devices适用于 Android 的附近连接 API - 不适用于某些设备
【发布时间】:2016-02-19 05:36:05
【问题描述】:

我正在使用此处提供的示例应用程序测试 Nearby 连接 API:https://github.com/googlesamples/android-nearby 似乎这不适用于某些设备。我成功地将三星 Galaxy S3 与 Nexus 7 双向连接(S3 作为主机,N7 作为从机,反之亦然)。但是,当我尝试将 Samusung Galaxy S3 连接到 Nexus 5 时,连接总是失败,状态码为 8005。

下面你可以看到slave(发现设备)为了连接到主机(广告设备)而调用的方法。

private void connectTo(String endpointId, final String endpointName) {
    debugLog("connectTo:" + endpointId + ":" + endpointName);

    // Send a connection request to a remote endpoint. By passing 'null' for the name,
    // the Nearby Connections API will construct a default name based on device model
    // such as 'LGE Nexus 5'.
    String myName = null;
    byte[] myPayload = null;
    Nearby.Connections.sendConnectionRequest(mGoogleApiClient, myName, endpointId, myPayload,
            new Connections.ConnectionResponseCallback() {
                @Override
                public void onConnectionResponse(String endpointId, Status status,
                                                 byte[] bytes) {
                    Log.d(TAG, "onConnectionResponse:" + endpointId + ":" + status);
                    if (status.isSuccess()) {
                        debugLog("onConnectionResponse: " + endpointName + " SUCCESS");
                        Toast.makeText(MainActivity.this, "Connected to " + endpointName,
                                Toast.LENGTH_SHORT).show();

                        mOtherEndpointId = endpointId;
                        updateViewVisibility(STATE_CONNECTED);
                    } else {
                        debugLog("onConnectionResponse: " + endpointName + " FAILURE. ResponseCode=" + status.getStatusCode() + " statusMessage=" + status.getStatusMessage() );
                    }
                }
            }, this);
}

我总是得到的结果是:
11-17 18:48:50.678 11133-11133/com.google.example.connectionsquickstart D/MainActivity:onConnectionResponse:三星 GT-I9300 失败。 ResponseCode=8005 statusMessage=null

有什么线索吗?

【问题讨论】:

    标签: android google-nearby


    【解决方案1】:

    您收到的错误是STATUS_NOT_CONNECTED_TO_ENDPOINT(来自Reference docs)。两台设备都需要连接到可以访问互联网的同一个 WiFi。

    【讨论】:

    • 不幸的是,事实并非如此。两台设备都连接到同一个 WiFi。如前所述,该代码适用于某些设备,但对于其他设备则不然。
    • 你可能想在他们的sample app repo上提交问题
    • 感谢您的建议。我提出了一个问题。
    【解决方案2】:

    我假设您说的是连接快速入门示例。在此处查看此 github 问题https://github.com/googlesamples/android-nearby/issues/6 .此示例中使用的 API 显然依赖于多播,这肯定取决于您的路由器,显然也取决于您的设备:

    显然你在 Nexus 7 上有这个,但在 Nexus 5 上没有: https://code.google.com/p/android/issues/detail?id=51195

    chuckd73...@gmail.com 这对我们来说是 Nexus 4 上的一个阻碍。我们的应用程序依赖于多播,不能以任何其他方式实现。有趣的是,Nexus 7 确实实现了这一点,但 Nexus 4 没有。

    2014 年 1 月 8 日 #3 jan.zibu...@gmail.com 这个问题在 Nexus 5 上仍然存在。

    所以我敢打赌,在你当前的 wifi 上,你可以将你的 nexus 7 连接到任何东西。

    需要明确的是,您在尝试接收多播数据包时可能会遇到问题:Android can not receive multicast packet

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-11
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多