私はアンドロイドアプリにGoogle Sign-in
を統合しようとしています。Android - GoogleサインインgetDisplayName()は新しいアカウントに表示名の代わりにメールを送信します。
はここに私のコードです:私はサインインして私のアプリの中に、私はAccountChooser
ダイアログで、それを選択することで、事前に設定されたアカウントを使用する場合はしようとすると、今
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PrefUtil.setTaskBarColored(this, R.color.treasure_black);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
loginHandler = new LoginHandler(this);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(AppIndex.API).build();
}
@OnClick(R.id.btn_login)
public void OnLoginButtonClick() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
DialogClass.showDialog(this, "Signing In");
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
} else {
DialogClass.dismissDialog(this);
}
}
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();
userName = acct.getDisplayName();
Log.i("userName",userName);
email = acct.getEmail();
Uri url=null;
if(acct.getPhotoUrl()!=null){
url = acct.getPhotoUrl();
}
String imageUrl=null;
if(url!=null && (!TextUtils.isEmpty(url.toString()))){
imageUrl=url.toString();
PrefUtil.putString(Constant.PreferenceKey.USER_IMAGE,imageUrl);
}
LoginRequestModel loginRequestModel = new LoginRequestModel(email, userName, imageUrl);
loginHandler.getUserDetails(loginRequestModel);
signOut();
} else {
DialogClass.dismissDialog(this);
}
}
、それが完璧に動作します。
しかし、AccountChooser
ダイアログで、私の代わりに、ユーザー名のuserName = acct.getDisplayName()
にAccount Chooser
のオプション「アカウントを追加」して、新しいアカウントを追加し、それは私に与えE-Mailを使用し、中に私はnullを与えた場合url = acct.getPhotoUrl()
私のアプリをログアウトして、同じアカウントをアカウントチューザーからSAMEアカウントを選択して使用すると、それは完全に機能し、理由がわかりません。
ご協力いただければ幸いです。
これを解決しましたか、これがなぜ起こったのですか? –
その前には運がありません。私がしたのは、Googleから名前やメールが届いているかどうかを確認することでした。メールを受け取ったら、アカウントの選択をもう一度開きました。 –