2017-09-25 191 views
0

我原本以爲是正確的Strategy.P2P_CLUSTER連接,而是我得到:的附近連接2.0是無法連接到同行

D/Meshy: onEndpointFound (we want to connect to someone!) (endpointId=CL36, serviceId=meshy.SERVICE_ID, endpointName=365589) 
W/Meshy: acceptConnection failed with 8011 STATUS_ENDPOINT_UNKNOWN 

這是奇怪的,從來沒有人說「不」連接請求。也許我的生命週期錯了?

val mEndpointDiscoveryCallback = object : EndpointDiscoveryCallback() { 
     // We found someone to connect to! 
     override fun onEndpointFound(endpointId: String, info: DiscoveredEndpointInfo) { 
      Log.d(TAG, "onEndpointFound (we want to connect to someone!) (endpointId=$endpointId, serviceId=${info.serviceId}, endpointName=${info.endpointName})") 
      if (SERVICE_ID == info.serviceId) { 
       Nearby.Connections.acceptConnection(mGoogleApiClient, endpointId, mPayloadCallback) 
         .setResultCallback { status -> 
          if (!status.isSuccess) { 
           Log.w(TAG, "acceptConnection failed with ${status.toReadable()}") 
          } else { 
           Log.d(TAG, "acceptConnection success") 
           endpoints.add(endpointId) 
          } 
         } 
      } else { 
       Log.w(TAG, "onEndpointFound ignoring unknown endpointId=$endpointId serviceId=${info.serviceId}") 
      } 
     } 

回答