Android 的附近连接 API - 不适用于某些设备
Nearby connection API for Android - not working for some devices
我正在使用此处提供的示例应用程序测试附近连接 API:https://github.com/googlesamples/android-nearby
这似乎不适用于某些设备。我成功地将 Samsung Galaxy S3 与 Nexus 7 双向连接(S3 作为主机,N7 作为从机,反之亦然)。但是,当我尝试将 Samusung Galaxy S3 连接到 Nexus 5 时,连接总是失败,状态代码为 8005。
下面是slave(发现设备)为了连接host(广告设备)调用的方法
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
有什么线索吗?
您收到的错误是 STATUS_NOT_CONNECTED_TO_ENDPOINT
(来自 Reference docs)。两台设备都需要连接到同一个可以上网的 WiFi。
我假设您在谈论连接快速入门示例。在此处查看此 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
This is a show stopper for us on the Nexus 4. Our app relies on multicast and cannot be implemented any other way. It's interesting that the Nexus 7 actually does have this implemented, but not the 4.
Jan 8, 2014 #3 jan.zibu...@gmail.com
The problem persists on the Nexus 5.
所以我敢打赌,在您当前的 wifi 上,您可以将您的 nexus 7 连接到任何设备。
需要说明的是,您在尝试接收多播数据包时可能会遇到问题:Android can not receive multicast packet
我正在使用此处提供的示例应用程序测试附近连接 API:https://github.com/googlesamples/android-nearby 这似乎不适用于某些设备。我成功地将 Samsung Galaxy S3 与 Nexus 7 双向连接(S3 作为主机,N7 作为从机,反之亦然)。但是,当我尝试将 Samusung Galaxy S3 连接到 Nexus 5 时,连接总是失败,状态代码为 8005。
下面是slave(发现设备)为了连接host(广告设备)调用的方法
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
有什么线索吗?
您收到的错误是 STATUS_NOT_CONNECTED_TO_ENDPOINT
(来自 Reference docs)。两台设备都需要连接到同一个可以上网的 WiFi。
我假设您在谈论连接快速入门示例。在此处查看此 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 This is a show stopper for us on the Nexus 4. Our app relies on multicast and cannot be implemented any other way. It's interesting that the Nexus 7 actually does have this implemented, but not the 4.
Jan 8, 2014 #3 jan.zibu...@gmail.com The problem persists on the Nexus 5.
所以我敢打赌,在您当前的 wifi 上,您可以将您的 nexus 7 连接到任何设备。
需要说明的是,您在尝试接收多播数据包时可能会遇到问题:Android can not receive multicast packet