【问题标题】:How to properly dismiss Google Play Games Account Picker?如何正确关闭 Google Play 游戏帐户选择器?
【发布时间】:2017-07-13 02:38:26
【问题描述】:

当用户按下登录按钮时,帐户选择器会启动。如果他们按下除了帐户选择器之外的屏幕上的其他位置,它会关闭并 logcat 报告:

W/SignInActivity: onSignInFailed()... Sign in failed during 2 ==> Returning non-OK result: 0 W/AutoManageHelper: Unresolved error while connecting client. Stopping auto-manage.

然后调用 OnActivityResult()

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task =
                GoogleSignIn.getSignedInAccountFromIntent(intent);

        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            onConnected(account);
        } catch (ApiException apiException) {
            String message = apiException.getMessage();
            if (message == null || message.isEmpty()) {
                message = getString(R.string.signin_other_error);
            }

            onDisconnected();

            if(message.startsWith("13")){
                new AlertDialog.Builder(MainActivity.this)
                        .setTitle(R.string.alert_nologin_title)
                        .setMessage(R.string.alert_nologin_message)
                        .setNeutralButton(android.R.string.ok, null)
                        .show();
            }else{
                new AlertDialog.Builder(this)
                        .setMessage(message)
                        .setNeutralButton(android.R.string.ok, null)
                        .show();
            }
        }
    }
}

发生这种情况时,AlertDialog.Builder 正在显示一条消息 13:,因此我包含了 if 语句来解决和针对这种特定情况。

该应用已在 Google Play 管理中心注册,可以正常连接,没有问题。以前这个问题也会导致应用程序崩溃,但现在不再是这种情况了,用户现在可以随意关闭或登录/注销,并且应用程序将保持稳定。

如果需要更多信息,该项目托管在 GitHub 上:https://github.com/MDodd423/TapAttack

感谢您的帮助。

【问题讨论】:

    标签: android google-play-services google-play-games


    【解决方案1】:

    请注意,在调用特定的 Google 服务之前,您可能首先需要在 Google Developer Console 中注册您的应用。如果你还没有完成,set up a project and application in the API Console。

    然后,检查Accessing Google APIs,其中还讨论了启动automatically managed connection。您的GoogleApiClient 实例将在您的活动调用onStart() 后自动连接,并在调用onStop() 后断开连接。

    查看此相关 SO 帖子以获取更多见解:

    【讨论】:

    • 应用在控制台注册,连接正常。我没有 onStart 或 onStop 我相信 .enableAutoManage 可以处理。我添加了有关该问题的更多信息,感谢您的回复。
    猜你喜欢
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多