9

我正在使用此处提供的示例应用程序测试 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:Samsung GT-I9300 FAILURE。响应代码=8005 状态消息=空

有什么线索吗?

4

2 回答 2

1

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

于 2015-11-19T20:52:41.883 回答
0

我假设您正在谈论连接快速入门示例。在此处查看此 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 无法接收多播数据包

于 2015-11-25T17:41:51.373 回答