如何在Android中正确设置Google Play签名?

发布于 2025-01-28 14:06:13 字数 1577 浏览 3 评论 0原文

我在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);
    }

It Loads the GP Games

Then this happens

EDIT

Now after following the suggested methods, the SignIn dialogue closes immediately without showing any errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2025-02-04 14:06:13

apiexception的消息并不是真正讲述:

String message = apiException.getMessage();

要调试apiexception的状态宁愿很有帮助:

int StatusCode = apiException.getStatusCode();

请参阅

另一个怀疑是缺失或过时的 google-services.json 。它需要添加匹配(调试或释放或两个​​)键指纹,该指纹是用于签名apk软件包的密钥。即使不使用Firebase,也必须在此处设置该项目,以添加密钥指纹并获得该配置文件(在字符串资源中必须有一些google> google> google_app_id Play Services Services插件将从该配置文件中生成)。


状态4表示 sign_in_required

客户端试图连接到服务,但未签署用户。

客户可以选择在不使用API​​的情况下继续。

google_app_id或不匹配的键指纹的google_app_id的失败身份验证提示。认为一个人不需要许可即可使用googlesignInclient ...获得当前签名的Google帐户...因此,这可能意味着,API客户端未登录Google Play。

The message of the ApiException is not really telling:

String message = apiException.getMessage();

To debug this, the status of the ApiException would rather be helpful:

int StatusCode = apiException.getStatusCode();

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 some google_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:

The client attempted to connect to the service but the user is not signed in.

The client may choose to continue without using the API.

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 the GoogleSignInClient... so this likely means, the API client not being signed in to Google Play.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文