如何在Android中检查电话身份验证用户? [英] How to check for a phone auth user in Android?

查看:78
本文介绍了如何在Android中检查电话身份验证用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修改此 onStart()方法以获取单独的Phone auth用户数据库?

How to modify this onStart() method to get my separate Phone auth user database?

@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的 UserInfo 类包含名为 getProviderId(),它返回提供者的ID.

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. One more thing to note is that each UserInfo class contains a method named getProviderId() which returns the ID of the provider.

一个可行的代码解决方案可能看起来像这样:

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

例如,如果将来您将使用通过Firebase进行Google身份验证,则应检查以下内容:

If in the future you'll use for example, Google authentication with Firebase, then you should check against:

GoogleAuthProvider.PROVIDER_ID

这篇关于如何在Android中检查电话身份验证用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆