android firebase 12.0.0 - mAuth.getCurrentUser().getProvider() method is removed, how to get provider names?

三世轮回 提交于 2019-12-06 06:39:27

问题


in firebase_version = '11.8.0' there was a method called mAuth.getCurrentUser().getProviders() i could call to get the list of provider names. so for email provider it was "password" and for facebook is was "facebook.com", etc

the method call was like this:

final FirebaseUser currentUser = mAuth.getCurrentUser()

    for (String provider : this.currentUser.getProviders()) {
      //i was looping over all the providers this way, and then storing the provider string in my db
    }

but now in the latest firebase_version = '12.0.0' the method getProviders() is not available. How can i get the provider names as string ?


回答1:


Use FirebaseUser.getProviderData(). It returns a list of UserInfo, each contains a string Provider ID.

For example:

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    List<? extends UserInfo> infos = user.getProviderData();
    for (UserInfo ui : infos) {
        if (ui.getProviderId().equals(GoogleAuthProvider.PROVIDER_ID)) {
            return true;
        }
    }


来源:https://stackoverflow.com/questions/49484003/android-firebase-12-0-0-mauth-getcurrentuser-getprovider-method-is-removed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!