如何在Android中正确设置Google Play签名?
我在Android开发了一款游戏。我试图实现GooglePlay Signin,但显示出错误。我无法调试此错误。我尝试在模拟器以外的其他手机模型中安装该应用程序。
代码:
public void startSignInIntent() {
startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task =
GoogleSignIn.getSignedInAccountFromIntent(intent);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
} catch (ApiException apiException) {
String message = apiException.getMessage();
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();
}
}
super.onActivityResult(requestCode, resultCode, intent);
}
编辑
现在遵循建议的方法后,签名对话立即关闭而不会显示任何错误。
I developed a game in android. I tried to implement the GooglePlay SignIn but it shows an error. I'm not able to debug this error. I tried installing the app in different phone models other than emulators.
Code:
public void startSignInIntent() {
startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task =
GoogleSignIn.getSignedInAccountFromIntent(intent);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
} catch (ApiException apiException) {
String message = apiException.getMessage();
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();
}
}
super.onActivityResult(requestCode, resultCode, intent);
}
EDIT
Now after following the suggested methods, the SignIn dialogue closes immediately without showing any errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
apiexception
的消息并不是真正讲述:要调试
apiexception
的状态宁愿很有帮助:请参阅
另一个怀疑是缺失或过时的 google-services.json 。它需要添加匹配(调试或释放或两个)键指纹,该指纹是用于签名
apk
软件包的密钥。即使不使用Firebase,也必须在此处设置该项目,以添加密钥指纹并获得该配置文件(在字符串资源中必须有一些google> google> google_app_id
Play Services Services插件将从该配置文件中生成)。状态
4
表示 sign_in_required :google_app_id
或不匹配的键指纹的google_app_id
的失败身份验证提示。认为一个人不需要许可即可使用googlesignInclient
...获得当前签名的Google帐户...因此,这可能意味着,API客户端未登录Google Play。The message of the
ApiException
is not really telling:To debug this, the status of the
ApiException
would rather be helpful:See the documentation; It could have to do with oAuth2 scopes; but the question lacks the code where the
GoogleSignInClient
is being constructed (might be relevant to reproduce the error).Another suspicion would be a missing or outdated google-services.json. It needs to have the matching (debug or release or both) key fingerprints added, of the keys used to sign that
APK
package. Even if not using Firebase, one has to setup the project there, in order to add the key fingerprints and to obtain that one config file (there has to be somegoogle_app_id
in the string resources and this is exactly what the Play Services Plugin would generate from that config file).Status
4
means SIGN_IN_REQUIRED:A failed authentication hints for
google_app_id
or the key fingerprints not matching. Think one does not require permission to get the currently signed-in Google account with theGoogleSignInClient
... so this likely means, the API client not being signed in to Google Play.