2017-02-21 7 views
1

私のplay-services-nearbyをバージョン'10.2.0 'にアップデートすると、EndpointDiscoveryListenerとConnectionRequestListenerがインタフェースから抽象クラスに変更され、EndClientをEndpointDiscoveryListenerで拡張し、内部クラス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クラスのコンテキストで最も簡単なアプローチは、抽象クラスを実装するクラスに2つの新しいフィールドを追加し、既存の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を実行しましたか?それは私のために働かなかったので。もしあなたが私に新しいものを送ってくれたら?またはサンプルを更新しました –

+1

サンプルが更新されました:https://github.com/playgameservices/android-basic-samplesしかし、StopDiscovery()またはstopAdvertising()を呼び出すとPlayサービスがクラッシュすることがある既知のバグがあります。彼らはそれを修正するために取り組んでおり、次のSDKの更新になります。 –

+0

エラーが修正された場合はお知らせください –

関連する問題