首页 文章

适用于Android的附近连接API - 不适用于某些设备

提问于
浏览
8

我正在使用此处提供的示例应用程序测试Nearby connection 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 . ResponseCode = 8005 statusMessage = null

有什么线索是怎么回事?

2 回答

  • 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实际上已经实现了这一点,但不是4月8日,2014年#3 jan.zibu ... @ gmail.com问题仍然存在于Nexus 5上 .

    所以我敢打赌,在你目前的无线网络上,你可以将你的nexus 7连接到任何东西 .

    为了清楚起见,您可能在尝试接收多播数据包时遇到问题:Android can not receive multicast packet

  • 1

    你得到的错误是 STATUS_NOT_CONNECTED_TO_ENDPOINT (来自Reference docs) . 两个设备都需要连接到具有互联网接入的相同WiFi .

相关问题