2016-08-14 2 views
1

Google 프로그래밍을 처음 사용하는 사람은 안드로이드 프로그래밍에 익숙하지 않기 때문입니다. 나는 Google 게임 서비스를 구현하고 내 응용 프로그램에 리더 보드를 표시하려고 시도했습니다. 게임은 짐작할 수 있겠지만 Google의 설명서와 함께 따라야하는 어려움이 있습니다.Google Play 게임 서비스 구현 - 사용자 로그인 허용 방법

버튼을 설정했는데 탭 한 상태에서 사용자가 로그인 할 수있게하고 나중에 로그 아웃 할 때까지 사용자를 로그온 상태로 두려고합니다. 나는 문서 다음이 프로그래밍 한 :

public class MainActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { 

    Button bLeaderboard; 

    private GoogleApiClient mGoogleApiClient; 

    private static int RC_SIGN_IN = 9001; 

    private boolean mResolvingConnectionFailure = false; 
    private boolean mAutoStartSignInflow = true; 
    private boolean mSignInClicked = false; 


@Override 
@SuppressLint("NewApi") 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    bLeaderboard = (Button) findViewById(R.id.bLeaderboard); 
    bLeaderboard.setOnClickListener(this); 

    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .addApi(Games.API).addScope(Games.SCOPE_GAMES) 
      .build(); 
} 

@Override 
public void onClick(View v) { 
    switch (v.getId()) { 

     case R.id.bLeaderboard: 

      mSignInClicked = true; 
      mGoogleApiClient.connect(); 
} 

} 

문제는 그 나는 리더 버튼 응용 프로그램 충돌을 누르고이 오류 메시지를받을 때마다 :

AndroidRuntime를 : 치명적인 예외 : 주요 프로세스 : com.example.game, PID : 26284 java.lang.IllegalStateException : 치명적인 개발자 오류가 발생했습니다. 자세한 정보는 로그를 확인하십시오. com.google.android.gms.common.internal.zzd $ zza.zzc (알 수없는 출처) com.google.android.gms.common.internal.zzd $ zza.zzv (알 수없는 출처) at com. google.android.gms.common.internal.zzd $ zze.zzasf (알 수없는 출처) com.google.android.gms.common.internal.zzd $ zzd.handleMessage (알 수없는 출처) android.os.Handler. dispatchMessage (Handler.java:102) android.os.Looper.loop (Looper.java:148)에서 android.app.ActivityThread.main (ActivityThread.java:5417)에서 에서 java.lang.reflect.Method의 . 호출 (네이티브 메소드) at com.andro 나는 또한 수 없었습니다

id.internal.os.ZygoteInit $ MethodAndArgsCaller.run com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)에서 (ZygoteInit.java:726) 이 세 가지 구현 방법과 무엇을 이해한다 내가 말했듯이 구글의 문서를 제외하고 여기에 대한 자습서를 찾을 수 없어으로 어떤 도움을 크게 감사

@Override 
public void onConnected(@Nullable Bundle bundle) { 
} 

@Override 
public void onConnectionSuspended(int i) { 
} 

@Override 
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 

} 

를, 나는 이해하기 위해 투쟁하고 따르다.

답변

1

이 또한 게임 서비스 콘솔을 플레이 구글에 테스터의 이메일 ID를 선포 기억 올바르게

public class MainActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { 

// Client used to interact with Google APIs 
private GoogleApiClient mGoogleApiClient; 
private static int RC_SIGN_IN = 9001; 

private boolean mResolvingConnectionFailure = false; 
private boolean mAutoStartSignInflow = true; 
private boolean mSignInClicked = false; 
GameHelper gameHelper; 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 


    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .addApi(Games.API).addScope(Games.SCOPE_GAMES) 
      .build(); 
    gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES); 
    gameHelper.enableDebugLog(true); 
    gameHelper.setup(new GameHelper.GameHelperListener() { 
     @Override 
     public void onSignInFailed() { 
     Toast.makeText(getApplicationContext(),"Please Check Your Internet Connection!",Toast.LENGTH_LONG).show(); 
     } 

     @Override 
     public void onSignInSucceeded() { 
      Toast.makeText(getApplicationContext(),"Signed in Succeed",Toast.LENGTH_LONG).show(); 
     } 
    }); 



    setContentView(view); 

    //for load all Score card 



    scorecard=(Button)findViewById(R.id.score_card); 
    scorecard.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 


      startActivityForResult(Games.Leaderboards.getAllLeaderboardsIntent(mGoogleApiClient), 1); 

     } 
    }); 





} 
private boolean isScoreResultValid(final Leaderboards.LoadPlayerScoreResult scoreResult) { 
    return scoreResult != null && GamesStatusCodes.STATUS_OK == scoreResult.getStatus().getStatusCode() && scoreResult.getScore() != null; 
} 



@Override 
protected void onStart() { 
    super.onStart(); 
    mGoogleApiClient.connect(); 
} 

@Override 
protected void onStop() { 
    super.onStop(); 
    mGoogleApiClient.disconnect(); 
} 

@Override 
public void onConnected(Bundle connectionHint) { 
    // The player is signed in. Hide the sign-in button and allow the 
    // player to proceed. 
    // now submit your high_score 
    Games.Leaderboards.submitScore(mGoogleApiClient,getResources().getString(R.string.leaderboard_easy),high_score); 

} 

@Override 
public void onConnectionFailed(ConnectionResult connectionResult) { 
    if (mResolvingConnectionFailure) { 
     // already resolving 
     return; 
    } 

    // if the sign-in button was clicked or if auto sign-in is enabled, 
    // launch the sign-in flow 
    if (mSignInClicked || mAutoStartSignInflow) { 
     mAutoStartSignInflow = false; 
     mSignInClicked = false; 
     mResolvingConnectionFailure = true; 

     // Attempt to resolve the connection failure using BaseGameUtils. 
     // The R.string.signin_other_error value should reference a generic 
     // error string in your strings.xml file, such as "There was 
     // an issue with sign-in, please try again later." 
     /*if (!BaseGameUtils.resolveConnectionFailure(this, 
       mGoogleApiClient, connectionResult, 
       RC_SIGN_IN, "Sign in error")) { 
      mResolvingConnectionFailure = false; 
     }*/ 
    } 

    // Put code here to display the sign-in button 
} 

@Override 
public void onConnectionSuspended(int i) { 
    // Attempt to reconnect 
    mGoogleApiClient.connect(); 
} 



protected void onActivityResult(int requestCode, int resultCode, 
           Intent intent) { 
    if (requestCode == RC_SIGN_IN) { 
     mSignInClicked = false; 
     mResolvingConnectionFailure = false; 
     if (resultCode == RESULT_OK) { 
      mGoogleApiClient.connect(); 
     } else { 
      // Bring up an error dialog to alert the user that sign-in 
      // failed. The R.string.signin_failure should reference an error 
      // string in your strings.xml file that tells the user they 
      // could not be signed in, such as "Unable to sign in." 
      BaseGameUtils.showActivityResultError(this, 
        requestCode, resultCode, R.string.signin_failure); 
     } 
    } 
} 
// Call when the sign-in button is clicked 
private void signInClicked() { 
    mSignInClicked = true; 
    mGoogleApiClient.connect(); 
} 

// Call when the sign-out button is clicked 
private void signOutclicked() { 
    mSignInClicked = false; 
    Games.signOut(mGoogleApiClient); 
} 

} 
+0

나를 위해 작동 .. –

관련 문제