Android Studioを使って作ったゲームにGoogle Play Game Servicesのリーダーボードを設置したのですが
リーダーボードを呼び出すと落ちてしまいます。
状態は
グーグルコンソール管理画面で登録は全部済んでいます。
ゲームを起ち上げた時Google Play Gameの接続は問題なくできています。
リーダーボードを呼び出すstartActivityForResultで落ちます。
ネットで色々調べましたが同じ悩みの方は多数いますが解決案が見つかりません。
分かる方アドバイスよろしくお願いします。
環境)
Android Studio 3.0.1
PC Mac
app/build.gradle
dependencies { compile 'com.google.android.gms:play-services-games:10.0.0' }
QuizActivity.java
public class QuizeActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{ private GoogleApiClient mGoogleApiClient; private boolean mIntentInProgress; private int REQUEST_CODE = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quize); //GoogleApiClient初期設定 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 == REQUEST_CODE){ mIntentInProgress = false; if (resultCode != RESULT_OK){ return; } if (!mGoogleApiClient.isConnected()){ mGoogleApiClient.reconnect(); } } } //nextボタンを押した時の挙動 public void goNext(View v){ if (quizeNum < quizeList.size()-1){ // if (quizeNum < 5-1){ if (resultNum){ quizeList = new ArrayList<>(); quizeNum++; hazureList = new ArrayList<>(); quizeGet(); judgDisplay(2); numberDisplay(); buttonEnabled(true,true,true,false); buttonDisplay(); descriDisplay(); v.invalidate(); }else { resultDisplay(); if (mGoogleApiClient.isConnected()){ Games.Leaderboards.submitScore(mGoogleApiClient, String.valueOf(R.string.leaderboard_id), quizeNum); switch (quizeNum){ case 50: Games.Achievements.unlock(mGoogleApiClient, String.valueOf(R.string.achievements_id50)); break; } }else { mGoogleApiClient.connect(); ★ここで落ちます。↓ startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient), 1); startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient, getString(R.string.leaderboard_id)),REQUEST_CODE); } } }else { //ここに最期のメッセージを入れる lastDialog(); SlideManager.saveInt(getApplicationContext(),"highscore", quizeNum + 1); } } @Override public void onConnected(@Nullable Bundle bundle) { //Player情報取得 Player player = Games.Players.getCurrentPlayer(mGoogleApiClient); String displayName = "???"; if (player != null){ displayName = player.getDisplayName(); } Toast.makeText(getApplicationContext(),String.format("%s でログインしています", displayName), Toast.LENGTH_SHORT).show(); } @Override public void onConnectionSuspended(int i) { mGoogleApiClient.connect(); } @Override public void onConnectionFailed(@NonNull 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(); } } } }
errorメッセージ
FATAL EXCEPTION: main Process: com ○○ PID: 31343 java.lang.IllegalStateException: GoogleApiClient must be connected. at com.google.android.gms.common.internal.zzac.zza(Unknown Source) at com.google.android.gms.games.Games.zzb(Unknown Source) at com.google.android.gms.games.Games.zzi(Unknown Source) at com.google.android.gms.games.internal.api.AchievementsImpl.getAchievementsIntent(Unknown Source) at com.○○.QuizeActivity.goNext(QuizeActivity.java:289) at com.○○.QuizeActivity.onClick(QuizeActivity.java:469)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。