GOOGLE登入
第八步:宣告
GoogleSignInClient mgoogleSignInClient;
int RC_SIGN_IN;
第九步:在程式新增以下代碼(可放在按鈕事件裡)
GoogleSignInOptions gso=new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestEmail()
.build();
mgoogleSignInClient = GoogleSignIn.getClient(this,gso);
Intent signInIntent =mgoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent,RC_SIGN_IN);
```
第十步:在onActivityResult寫下
if(requestCode==RC_SIGN_IN){
Tasktask=GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
第十一步:添加一個funtion
private void handleSignInResult(TaskcompletedTask){
try{
GoogleSignInAccount account=completedTask.getResult(ApiException.class);
} catch (ApiException e) {
e.printStackTrace();
}
}