2017-11-29 16 views
0

Google의 로그인 방식을 변경하면 로그인이 오래 걸릴 수 있습니다. 로그인을 구현하면 GoogleApiClient이 던져졌지만 이제는 달라집니다 GoogleSignInClient 사용자가 로그인하거나 업적을 달성 할 때 팝업 뷰를 설정하는 방법에 대한 단서가 없습니다. 심지어 구글 문서 도구에서이에 대한 좋은 설명이 없기 때문에 어느 하나가setViewForPopUp (보기) google api (11.6.0) Google Play 로그인

//google variable 
private static int RC_SIGN_IN = 9001; 
private static final int RC_ACHIEVEMENT_UI = 9003; 
GoogleApiClient googleApiClient; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

} 

public void SignIn(View view) { 
    GoogleSignInClient signInClient = GoogleSignIn.getClient(this, 
      GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); 
    Intent intent = signInClient.getSignInIntent(); 
    startActivityForResult(intent, RC_SIGN_IN); 
} 

private void signInSilently() { 
    GoogleSignInClient signInClient = GoogleSignIn.getClient(this, 
      GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); 
    signInClient.silentSignIn().addOnCompleteListener(this, 
      new OnCompleteListener<GoogleSignInAccount>() { 
       @Override 
       public void onComplete(@NonNull Task<GoogleSignInAccount> task) { 
        if (task.isSuccessful()) { 
         // The signed in account is stored in the task's result. 
         GoogleSignInAccount signedInAccount = task.getResult(); 
        } else { 
         // Player will need to sign-in explicitly using via UI 
        } 
       } 
      }); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    signInSilently(); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    Toast.makeText(MainActivity.this, String.valueOf(requestCode), Toast.LENGTH_SHORT).show(); 

    if (requestCode == RC_SIGN_IN) { 
     GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
     Log.d("fuck", String.valueOf(result)); 
     // Toast.makeText(MainActivity.this,String.valueOf(result),Toast.LENGTH_SHORT).show(); 
     if (result.isSuccess()) { 
      // The signed in account is stored in the result. 
      Toast.makeText(MainActivity.this, "Succesfull", Toast.LENGTH_SHORT).show(); 

      GoogleSignInAccount signedInAccount = result.getSignInAccount(); 
     } else { 
      String message = result.getStatus().getStatusMessage(); 
      if (message == null || message.isEmpty()) { 
       message = getString(R.string.signin_other_error); 
      } 
      new AlertDialog.Builder(this).setMessage(message) 
        .setNeutralButton(android.R.string.ok, null).show(); 
     } 
    } 
} 

public void achievement(View view) { 

    Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this)) 
      .getAchievementsIntent() 
      .addOnSuccessListener(new OnSuccessListener<Intent>() { 
       @Override 
       public void onSuccess(Intent intent) { 
        startActivityForResult(intent, RC_ACHIEVEMENT_UI); 
       } 
      }); 
} 

public void unlock(View view) { 
    Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this)) 
      .unlock(getString(R.string.achievement_newbie)); 
} 

답변

5

확인을 사전에 UR 답변 덕분에 게시하시기 바랍니다 알고 그래서 난 시도의 커플을주고 나서 대답을 자신을 가지고 당신이 할 수있는 일은 이후 task.getResult()의 성공적인 로그인은 객체를 반환 할 것이고 getGamesClient 메서드를 전달하면 GamesClient 객체를 반환하고 해당 객체를 사용하면 setViewForPopups 메서드를 호출 할 수 있습니다. 명확한 코드는 다음과 같습니다.

private void signInSilently() { 
    GoogleSignInClient signInClient = GoogleSignIn.getClient(this, 
      GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); 
    signInClient.silentSignIn().addOnCompleteListener(this, 
      new OnCompleteListener<GoogleSignInAccount>() { 
       @Override 
       public void onComplete(@NonNull Task<GoogleSignInAccount> task) { 
        if (task.isSuccessful()) { 
         // The signed in account is stored in the task's result. 
         GoogleSignInAccount signedInAccount = task.getResult(); 
         GamesClient gamesClient =Games.getGamesClient(MainActivity.this,signedInAccount); 
         gamesClient.setViewForPopups(findViewById(R.id.textview)); 
        } else { 
         // Player will need to sign-in explicitly using via UI 
        } 
       } 
      }); 
}