2017-02-21 40 views
1

更新我的播放服務,就近版本'10 .2.0' ,它改變從界面到抽象類的EndpointDiscoveryListener和ConnectionRequestListener,我EndpointDiscoveryListener延長NearbyClient並宣佈內部類ConnectionRequestListener,現在我看到AppIdentifier已過時過,我搜索了很多在谷歌,但我找不到任何新的例子, 這裏是我的代碼,我從GitHub playgameservices改變:如何在新的play-services-nearby中實現抽象類EndpointDiscoveryListener和ConnectionRequestListener?

public class NearbyClient extends Connections.EndpointDiscoveryListener implements 
     GoogleApiClient.ConnectionCallbacks, 
     GoogleApiClient.OnConnectionFailedListener, 
     Connections.MessageListener { 


    private class OnConnectionRequest extends Connections.ConnectionRequestListener { 

    private NearbyClient mNearbyClient; 

    OnConnectionRequest(NearbyClient nearbyClient) 
    { 
     this.mNearbyClient = nearbyClient; 
    } 

    @Override 
    public void onConnectionRequest(final String remoteEndpointId, final String remoteEndpointName, byte[] payload) { 
     Log.d(TAG, "onConnectionRequest:" + remoteEndpointId + 
       ":" + remoteEndpointName); 

     if (mIsHost) { 
      // The host accepts all connection requests it gets. 
      byte[] myPayload = null; 
      Nearby.Connections.acceptConnectionRequest(mGoogleApiClient, remoteEndpointId, 
        myPayload, mNearbyClient).setResultCallback(new ResultCallback<Status>() { 
       @Override 
       public void onResult(Status status) { 
        Log.d(TAG, "acceptConnectionRequest:" + status + ":" + remoteEndpointId); 
        if (status.isSuccess()) { 
         Toast.makeText(mContext, "Connected to " + remoteEndpointName, 
           Toast.LENGTH_SHORT).show(); 

         // Record connection 
         HeroParticipant participant = new HeroParticipant(remoteEndpointId, remoteEndpointName); 
         mConnectedClients.put(remoteEndpointId, participant); 

         // Notify listener 
         mListener.onConnectedToEndpoint(remoteEndpointId, remoteEndpointName); 
        } else { 
         Toast.makeText(mContext, "Failed to connect to: " + remoteEndpointName, 
           Toast.LENGTH_SHORT).show(); 
        } 
       } 
      }); 
     } else { 
      // Clients should not be advertising and will reject all connection requests. 
      Log.w(TAG, "Connection Request to Non-Host Device - Rejecting"); 
      Nearby.Connections.rejectConnectionRequest(mGoogleApiClient, remoteEndpointId); 
     } 
    } 

} 

的代碼的其餘部分是相同的例子。 實施新版本的最佳方式是什麼?
它顯示我「不幸的是,Google Play服務已停止」,當我想作爲客戶端連接時, 什麼是棄用新版本?

回答

1

在NearbyClient類的上下文中,最簡單的方法是向類中添加兩個新字段來實現抽象類,並簡單地調用現有的onConnectionRequest和onEndpointFound/Lost。

當設備ID參數不再暴露時,引入了10.2中的混淆。在大多數情況下,這是應用程序必須做的無意義的簿記,所以現在在10.2中,您不必跟蹤設備ID!

private Connections.ConnectionRequestListener myConnectionRequestListener = 
     new Connections.ConnectionRequestListener() { 
      @Override 
      public void onConnectionRequest(String remoteEndpointId, String 
        remoteEndpointName, byte[] bytes) { 
       NearbyClient.this.onConnectionRequest(remoteEndpointId, 
         remoteEndpointName, bytes); 
      } 
     }; 
private Connections.EndpointDiscoveryListener myEndpointDiscoveryListener = 
     new Connections.EndpointDiscoveryListener() { 
      @Override 
      public void onEndpointFound(String endpointId, 
             String serviceId, 
             String name) { 
       NearbyClient.this.onEndpointFound(endpointId,serviceId, 
         name); 
      } 

      @Override 
      public void onEndpointLost(String remoteEndpointId) { 
       NearbyClient.this.onEndpointLost(remoteEndpointId); 
      } 
     }; 

我會在本週晚些時候嘗試8位藝術家來更新它與10.2一起工作。與此同時,請隨時提交拉請求,如果你得到它的第一個:)。

+0

你運行8bitartist?因爲它不適合我。如果你確實請給我發送新的?或更換在github –

+1

樣本已更新:https://github.com/playgameservices/android-basic-samples有一個已知的bug但是,播放服務有時會打電話時stopDiscovery()或stopAdvertising()崩潰。他們正在修復它,並將在下一次SDK更新中。 –

+0

請讓我知道,如果錯誤糾正 –