首页 > 解决方案 > Google Play 游戏服务在登录期间询问权限

问题描述

我已经在我的应用中实现了 Google Play 游戏服务。但是,当我在静默登录失败时调用交互式登录时,应用程序会询问权限:

在此处输入图像描述

当我为我的帐户打开静默登录时,它可以正常工作。但是,使用交互式登录会询问这些权限,并且用户需要按允许。

我希望它在选择帐户后登录,而不是询问权限。

我的代码:

private void signIn() {
   GoogleSignInOptions signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN;
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
    if (GoogleSignIn.hasPermissions(account, signInOptions.getScopeArray())) {
        // Already signed in.
        // The signed in account is stored in the 'account' variable.
        GoogleSignInAccount signedInAccount = account;
    } else {
        // Haven't been signed-in before. Try the silent sign-in first.
        GoogleSignInClient signInClient = GoogleSignIn.getClient(context, signInOptions);
        signInClient.silentSignIn().addOnCompleteListener(context, new OnCompleteListener<GoogleSignInAccount>() {
            @Override
            public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
                if (task.isSuccessful()) {
                    // The signed in account is stored in the task's result.
                    GoogleSignInAccount signedInAccount = task.getResult();
                } else {
                    Intent intent = signInClient.getSignInIntent();
                    startActivityForResult(intent, RC_SIGN_IN);
                    // Player will need to sign-in explicitly using via UI.
                    // See [sign-in best
                    // practices](http://developers.google.com/games/services/checklist) for
                    // guidance on how and when to implement Interactive Sign-in,
                    // and [Performing Interactive
                    // Sign-in](http://developers.google.com/games/services/android/signin#performing_interactive_sign-in)
                    // for details on how to implement
                    // Interactive Sign-in.
                }
            }
        });
    }
}

标签: androidgoogle-play-servicesgoogle-play-games

解决方案


推荐阅读