简体   繁体   English

如何在 Android 中检查电话身份验证用户?

[英]How to check for a phone auth user in Android?

How to modify this onStart() method to get my separate Phone auth user database?如何修改此onStart()方法以获取我单独的电话身份验证用户数据库?

@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
    }
}

You can do that by calling UserInfo's getProviderData() method on the FirebaseUser object, to get the list of all authentication providers that are used by the authenticated user.您可以通过在FirebaseUser object 上调用 UserInfo 的getProviderData()方法来获取经过身份验证的用户使用的所有身份验证提供程序的列表。 One more thing to note is that each UserInfo class contains a method named getProviderId() which returns the ID of the provider.还有一点需要注意的是,每个UserInfo class 都包含一个名为getProviderId()的方法,该方法返回提供者的 ID。

A workable solution in code might look like this:代码中可行的解决方案可能如下所示:

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
    }
}

If in the future you'll use for example, Google authentication with Firebase , then you should check against:如果将来您将使用例如Google 身份验证 Firebase ,那么您应该检查:

GoogleAuthProvider.PROVIDER_ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM