我正在使用此处提供的示例应用程序测试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 回答
我假设您正在谈论连接 - 快速入门示例 . 请参阅此处的github问题https://github.com/googlesamples/android-nearby/issues/6 . 此示例中使用的API显然依赖于多播,这将依赖于您的路由器,显然也依赖于您的设备:
显然你有Nexus 7而不是Nexus 5:https://code.google.com/p/android/issues/detail?id=51195
所以我敢打赌,在你目前的无线网络上,你可以将你的nexus 7连接到任何东西 .
为了清楚起见,您可能在尝试接收多播数据包时遇到问题:Android can not receive multicast packet
你得到的错误是
STATUS_NOT_CONNECTED_TO_ENDPOINT
(来自Reference docs) . 两个设备都需要连接到具有互联网接入的相同WiFi .