android - 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.
}
}
});
}
}
解决方案
推荐阅读
- javascript - Aurelia 未正确转换 Set 和 Spread 运算符
- php - 邮件发送/失败后重定向并显示 Slim Flash 消息
- python - 使用 read_csv 只读奇数/数字列
- python - 在字符串中查找多个字符:python3
- java - 我试图找到定义为数字的对象的总和
- javascript - 为什么我编辑了一段时间后,Neovim 开始在我的文件中插入标签?
- javascript - 查找包含值的嵌套对象
- java - Spring boot jpa/hibernate 遇到列类型错误(json字段)
- python - Input as object python 3
- ruby - 无法在 ruby 中生成 RSA 公钥