Vijay
Vijay

Reputation: 1088

Check if the password is temporary on Firebase Android

I am trying to use the authData.getProviderData().get("isTemporaryPassword") method in Android API to check if the password is a temporary one. Though the method returns literally "true" while printing in log, if I use the method to redirect to a new Activity checking the if condition like

 if (authData.getProviderData().get("isTemporaryPassword")){
                        Intent intent = new Intent(MainActivity.this,PasswordReset.class);
                        Bundle bundle = new Bundle();
                        intent.putExtra("email",email.getText().toString());
                        intent.putExtra("password",password.getText().toString());
                        startActivity(intent);

it says "Incompatible Types Required: boolean Found:java.Lang.Object"

Am I missing something??

Upvotes: 0

Views: 118

Answers (2)

Douglas Drumond Kayama
Douglas Drumond Kayama

Reputation: 1974

The method #getProviderData() returns a Map<String, Object>. That's why when you #get() the value, it's an Object. Since you know this is a boolean, you can cast it to Boolean to use in the if condition:

if ((Boolean)authData.getProviderData().get("isTemporaryPassword")) { …

You can't put an Object inside an if condition, only boolean. You can put a Boolean though because autoboxing will take care and convert to boolean.

That also explains why testing for .equals(true) works. When you do that, the method .equals will do the conversion to test if the value stored in this object returned is equivalent to true.

Upvotes: 3

Vijay
Vijay

Reputation: 1088

This solution worked for me

if(authData.getProviderData().get("isTemporaryPassword").equals(true))

Since if() itself checks for a true condition, I didn't understand why equaling it to true solved my issue. I dont think this is a proper solution, but it's working.

Upvotes: 1

Related Questions