Google Play Game Servicesでランキング機能を実装したく参考サイトを参考にコードを書いてみたのですが強制終了してしまいます。
どこを修正すればよいのか、また他に参考になりそうなサイトがあれば教えてください。
よろしくお願いします。
java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information. at com.google.android.gms.common.internal.zzd$zza.zzc(Unknown Source) at com.google.android.gms.common.internal.zzd$zza.zzx(Unknown Source) at com.google.android.gms.common.internal.zzd$zze.zzasb(Unknown Source) at com.google.android.gms.common.internal.zzd$zzd.handleMessage(Unknown Source) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
import android.content.Intent; import android.content.IntentSender; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.games.Games; import com.google.android.gms.games.Player; public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener{ private GoogleApiClient mGoogleApiClient; private boolean mIntentInProgress; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } //初期設定 public void init() { // 各種リスナー登録とGoogleAPIで利用するAPIやスコープの設定 mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Games.API).addScope(Games.SCOPE_GAMES) .build(); } @Override protected void onStart() { super.onStart(); // 今回は画面が表示されるたびに必ず接続させる mGoogleApiClient.connect(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 100) { mIntentInProgress = false; if (resultCode != RESULT_OK) { // エラーの場合、resultCodeにGamesActivityResultCodes内の値が入っている return; } if (!mGoogleApiClient.isConnected()) { mGoogleApiClient.reconnect(); } } } @Override public void onConnected(Bundle bundle) { // プレイヤー情報取得 Player p = Games.Players.getCurrentPlayer(mGoogleApiClient); // 試しにプレイヤー名を表示 String displayName = "???"; if (p != null) { displayName = p.getDisplayName(); } Toast.makeText(this, String.format("%s でログインしています。", displayName), Toast.LENGTH_SHORT).show(); } @Override public void onConnectionSuspended(int i) { mGoogleApiClient.connect(); } @Override public void onConnectionFailed(ConnectionResult connectionResult) { int errorCode = connectionResult.getErrorCode(); // サインインしていない場合、サインイン処理を実行する if (errorCode == ConnectionResult.SIGN_IN_REQUIRED && !mIntentInProgress && connectionResult.hasResolution()) { try { mIntentInProgress = true; connectionResult.startResolutionForResult(this, 100); } catch (IntentSender.SendIntentException e) { mIntentInProgress = false; mGoogleApiClient.connect(); } } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。