I am Developing Firebase android application following tutorial of Udacity.
The setProviders method is marked deprecated by IDE, after going through documentation i was unable to find the solution. Is there any way out to solve the problem. Here is the code:
mMessagesDatabaseReference.addChildEventListener(mChildEventListener);
mAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null){
Toast.makeText(MainActivity.this,"You are signed in, Welcome", Toast.LENGTH_SHORT).show();
}else{
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setIsSmartLockEnabled(false)
.setProviders(
AuthUI.EMAIL_PROVIDER,
AuthUI.GOOGLE_PROVIDER
)
.build(),
RC_SIGN_IN);
}
}
};
}
UPDATE: You can now use setAvailableProviders()
instead of the deprecated setProviders()
Usage Example:
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build(),
new AuthUI.IdpConfig.FacebookBuilder().build()))
.build(),
RC_SIGN_IN);
Source: Firebase UI for Auth
Thanks @Alexey
The solution below will work but has been deprecated:
I'm also following the same tutorial and ended up here searching for the solution. I tried to find a solution myself and have found it. There are two overloaded method for setProviders(). The one with setProviders(String... providers) is deprecated. I used setProviders(List < IdpConfig > idpConfigs). Below is the code:
First create a List instance of IdpConfig, do this where you create instance of FirebaseDatabase. In other words, do this outside of all methods and inside your class.
List<AuthUI.IdpConfig> providers;
Write this in your onCreate() :
providers = new ArrayList<>();
Then replace your code with this:
mMessagesDatabaseReference.addChildEventListener(mChildEventListener);
mAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null){
Toast.makeText(MainActivity.this,"You are signed in, Welcome", Toast.LENGTH_SHORT).show();
}else {
providers.add(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build());
providers.add(new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build());
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setIsSmartLockEnabled(false)
.setProviders(providers)
.build(),
RC_SIGN_IN);
}
}
};
You're done! Have a good day :)
Just replace "setProvider" with "setAvailableProviders", it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With