java - 在android应用程序中集成gmail登录的问题?
问题描述
我想做一个 swiggy 类型的应用程序。我已经在我的登录屏幕中集成了 gmail 登录,它会在成功时更改为仪表板活动,但是当我单击帐户选项卡时,它会返回仪表板屏幕而不是帐户活动。请帮助......
如果您想要代码的任何部分,只需发表评论,我会更新
//login screen part
//check if already signed in using google
account = GoogleSignIn.getLastSignedInAccount(this);
if(account!=null) {
finish();
Intent intent = new Intent(this, DashboardActivity.class);
startActivity(intent);
return;
}
//onclicklistener added
//method
private void googleSignin() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
onActivity result(//params provided){
if(googleLogin){
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
googleLogin = false; //set to false so that it can be set true again if login is actually successful
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Signed in successfully, show authenticated UI.
sessionManager.setLogin(true);
googleLogin = true;
Intent intent = new Intent(this,DashboardActivity.class);
intent.putExtra("googleLogin", googleLogin);
startActivity(intent);
finish();
}
//Dashboard part
Intent i = new Intent(DashboardActivity.this ,MyAccountActivity.class);
i.putExtra("googleLogin", googleLogin);
startActivity(i);
//myaccount part
if(googleLogin){
GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(this);
if (acct != null) {
String personName = acct.getDisplayName();
//System.out.println(personName); working fine
account_name.setText(personName);
String personEmail = acct.getEmail();
//System.out.println(personEmail); fine
account_email.setText(personEmail);
account_mobile.setText("+91 1234567890");
// System.out.println(googleLogin);
// System.out.println(fbLogin);
}
}
解决方案
解决了这个问题。问题是当我尝试在我集成到我的应用程序中的我的帐户活动中显示它们时,gmail 无法提供要使用的帐户详细信息,这就是它不断崩溃的原因。代码是正确的,这就是为什么它没有给出任何错误我什至尝试记录它。它在那里显示了正确的细节,但仍然没有在文本视图中显示结果。所以我所做的是使用共享偏好。每次用户使用 gmail 登录时,详细信息都存储在其中,我在“我的帐户”活动中检索它,是的,它正确显示了结果。如果您需要更多帮助,请告诉我。
推荐阅读
- qt - 我的应用重新加载时如何自动播放音乐
- laravel - 如何从与自身有关系的项目中检索完整的关系?
- python - 访问views.py中的静态文件
- ruby-on-rails - Mime::Type::InvalidMimeType(“charset=utf-8”不是有效的 MIME 类型)
- javascript - 在使用 Redux 更新状态后渲染所有元素
- opengl - 如何在OpenGL中映射球体表面上的点击点?
- java - Android Studio 中的某些 Java 文件未显示在 GitHub Desktop 上
- python - 令牌键中的反斜杠
- spring-integration - 将 .json 文件转换为 Map 的问题
- lua - 像在 C 编程中一样在 lua 中创建位域结构