Android Google登录:检查用户是否已登录 [英] Android Google Sign In: check if User is signed in
问题描述
我正在寻找一种检查用户是否已经使用Google登录登录的方法.
I am looking for a way to check if my user already signed in with Google Sign In.
我支持多个日志记录API(Facebook,Google,自定义),因此我想构建一个静态帮助器方法,例如:
User.isUserLoggedIn()
I support several logging APIs (Facebook, Google, custom), so I would like to build a static helper method like:
User.isUserLoggedIn()
在Facebook上,我使用:
With Facebook I use:
if AccessToken.getCurrentAccessToken() != null {
return true
}
检查用户是否通过Facebook登录.
to check if the user is logged via Facebook.
在iOS上,我使用以下命令检查用户是否通过Google登录进行登录:
On iOS I use the following to check if the user is logged via Google Sign In:
GIDSignIn.sharedInstance().hasAuthInKeychain()
我的问题: Android上与iOS方法是否等效:
My question: Is there an equivalent on Android to the iOS method :
GIDSignIn.sharedInstance().hasAuthInKeychain()
吗?
我正在寻找一种不涉及回调的方法.
I am looking for a method that doesn’t involve a callback.
谢谢! 最高
推荐答案
您可以使用此功能
private boolean isSignedIn() {
return GoogleSignIn.getLastSignedInAccount(context) != null;
}
https://开发人员. google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignIn
公共静态GoogleSignInAccount getLastSignedInAccount(上下文上下文)
获取用户登录时使用的最后一个帐户.
Gets the last account that the user signed in with.
返回:最近一次成功登录的GoogleSignInAccount.如果 用户之前从未登录过或已退出/撤消访问权限, 返回null.
Returns: GoogleSignInAccount from last known successful sign-in. If user has never signed in before or has signed out / revoked access, null is returned.
这篇关于Android Google登录:检查用户是否已登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!