2014-11-06 2 views
-1

Google Play 서비스에 대한 Google 설명서를 따르려고했지만 Google 문서가 최악이기 때문에 불가능합니다.Google Play 게임 서비스의 작동 방식을 이해할 수 없습니까?

어쨌든 내 앱에서 프로젝트를 설정하고 Google Play 서비스를 추가해야했지만 사용자가 활동을 변경했을 때 연결된 상태를 유지하는 방법을 알지 못합니다.

나는, 나는 게임을 즐길 경우, GameActivity버튼 플레이에 다음 BaseGameActivity 및 사용자의 클릭을 확장 MainActivity를 열고 있고, 내가 경기를 끝내지 때 서비스 을 Google Play로 점수를 제출하려면 리더 보드,하지만 내가 연결할 수없는 것 같습니다.

나는 그럼 난 GameActivity에이 확장

public class MainActivity extends BaseGameActivity 

BaseGameActivity

와 MyActivity을 확장 : 다음

public GameActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, 
    GoogleApiClient.OnConnectionFailedListener 

에서 onCreate 사용에 대한이 :

// Create the Google Api Client with access to Plus and Games 
    mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext()) 
      .addOnConnectionFailedListener(this) 
      .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN) 
      .addApi(Games.API).addScope(Games.SCOPE_GAMES) 
        // add other APIs and scopes here as needed 
      .build(); 

그리고 t 암탉 내가 게임을 끝내면 나는 점수를 제출하려고 노력하지만, 나는 연결되어 있지 않은 것처럼 보인다.

if(mGoogleApiClient.isConnected()){ 
       Games.Achievements.unlock(mGoogleApiClient, 
         getString(R.string.app_name)); 
       Games.Leaderboards.submitScore(mGoogleApiClient, 
         getString(R.string.number_guesses_leaderboard), 
         clickCounter); 
      } 

답변

1

docs에 따르면, 당신은 mGoogleApiClient.connect() aswell를 호출해야합니다. 그들은 로그인을위한 버튼을 사용하는 것이 좋습니다,하지만 당신은 onStart()에서 그것을 할 수 있습니다 :

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

을 모두 잘 당신이 이미 구현하는 콜백 onConnected(Bundle connectionHint)를받을 수 있습니다 이동합니다.

1

플레이 게임 서비스는 실제로 프래그먼트를 염두에두고 만들어졌습니다. 액티비티 대신 단편을 사용하고 앱에 하나의 액티비티를 가져 오는 것이 필수적입니다 ...

+0

Google 문서 옆에 예제가 있습니까? – Zookey

+1

아니, 아니. 그러나 나는 문서가 왜 "최악"이라고 말하는지 이해하지 못합니다. 그것은 친절하게 잘하게된다. 설명서에서 권장하는대로 샘플을 기본으로 사용 했습니까? https://developer.android.com/google/play-services/games.html –

+0

설명서의 샘플을 기반으로 새로운 질문을 열었습니다. 로그인 한 후에도 오류가 발생합니다. http : // stackoverflow .com/questions/26804929/로그인 실패 - 네트워크 연결 및 시도 다시 확인 – Zookey

관련 문제