如何在 Android 中检查 phone 授权用户?
How to check for a phone auth user in Android?
如何修改此 onStart()
方法以获取我单独的 Phone auth 用户数据库?
@Override
protected void onStart() {
super.onStart();
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
if (firebaseAuth.getCurrentUser() != null) {
if(what condition required to check for phone auth){
startActivity(new Intent(EnterAs.this, UI_Main_User.class));
finish();
} else {
for email auth users
}
}
您可以通过调用 UserInfo 的 getProviderData() method on the FirebaseUser object, to get the list of all authentication providers that are used by the authenticated user. One more thing to note is that each UserInfo class contains a method named getProviderId() 来做到这一点,其中 returns 提供者的 ID。
一个可行的代码解决方案可能如下所示:
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
List<? extends UserInfo> userInfos = firebaseUser.getProviderData();
for (UserInfo userInfo : userInfos) {
String providerId = userInfo.getProviderId();
if (providerId.equals(PhoneAuthProvider.PROVIDER_ID)) {
//Your logic goes here
}
}
如果您将来要使用 Google authentication with Firebase,那么您应该检查:
GoogleAuthProvider.PROVIDER_ID
如何修改此 onStart()
方法以获取我单独的 Phone auth 用户数据库?
@Override
protected void onStart() {
super.onStart();
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
if (firebaseAuth.getCurrentUser() != null) {
if(what condition required to check for phone auth){
startActivity(new Intent(EnterAs.this, UI_Main_User.class));
finish();
} else {
for email auth users
}
}
您可以通过调用 UserInfo 的 getProviderData() method on the FirebaseUser object, to get the list of all authentication providers that are used by the authenticated user. One more thing to note is that each UserInfo class contains a method named getProviderId() 来做到这一点,其中 returns 提供者的 ID。
一个可行的代码解决方案可能如下所示:
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
List<? extends UserInfo> userInfos = firebaseUser.getProviderData();
for (UserInfo userInfo : userInfos) {
String providerId = userInfo.getProviderId();
if (providerId.equals(PhoneAuthProvider.PROVIDER_ID)) {
//Your logic goes here
}
}
如果您将来要使用 Google authentication with Firebase,那么您应该检查:
GoogleAuthProvider.PROVIDER_ID