附近的连接A​​PI为Android - 不适用于某些设备

问题描述:

我正在测试附近的连接A​​PI与示例应用程序在这里可用:https://github.com/googlesamples/android-nearby 似乎这不适用于某些设备。我在两个方向(S3作为主机,N7作为从机,反之亦然)成功连接了三星Galaxy S3和Nexus 7。但是,当我尝试将Samusung Galaxy S3连接到Nexus 5时,连接始终失败,状态代码为8005.附近的连接A​​PI为Android - 不适用于某些设备

下面您可以看到从设备(发现设备)调用的方法,以便连接到主机(广告设备)。

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

任何线索是怎么回事?

+0

是否与使用Nexus 7的Nexus 5的工作? https://productforums.google.com/forum/#!topic/nexus/o-UyGECxh2k –

我假设你在谈论连接快速入门示例。在这里看到这个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

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

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

只是要清楚,你可以尝试接收多播数据包的问题:Android can not receive multicast packet

+0

该文档清楚地说明了多播的需求:https://developers.google.com/nearby/connections/android/get-started“将多个Android设备连接到启用多播的同一网络” – Fabio

+0

@Ramps你有没有进步在这?我仍然遇到类似的问题 – Fabio

您遇到的错误是STATUS_NOT_CONNECTED_TO_ENDPOINT(来自Reference docs)。两台设备都需要连接到具有互联网接入的相同WiFi。

+0

不幸的是,这不是。两台设备都连接到同一个WiFi。如上所述,代码对于某些设备工作正常,但对于其他设备则不行。 – Ramps

+0

你可能想要提交他们的[示例应用程序回购]问题(https://github.com/googlesamples/android-nearby/issues) – MahlerFive

+0

感谢您的建议。我提出了一个问题。 – Ramps