简体   繁体   中英

How to remember login in firebase phone Auth even after app is uninstalled?

I want to remain user in login state even after the app is uninstalled. I use phone Auth for Firebase. From Stack overflow I found and tasted the following code for checking if user exist or not :

FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() {
    @Override
    public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
        FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
        if (firebaseUser != null) {
            Intent intent = new Intent(PhoneAuthActivity.this, MainActivityDriverLogin.class);
            startActivity(intent);
            finish();
        }else {
            Toast.makeText(PhoneAuthActivity.this, "Please Write Your Phone Number", Toast.LENGTH_SHORT).show();
        }
    }
};

and I set onStart :

mAuth.addAuthStateListener(authStateListener);

but, no luck, When I install app again, I have to use phone Number again.

I also tried in Manifests :

    android:allowBackup="true"
    android:fullBackupContent="true"

But, though the login has lost.

Is there any way for one time login in app, and remain login even the app unistalled or even clear cache from system ?

I think you are looking for smart lock feature in android. Google smartlock . You need to enable the feature on your authenitication. I assume you are using Firbase Authenitaction Ui using this method .setIsSmartLockEnabled(true)

AuthUI.getInstance()
                                    .createSignInIntentBuilder()
                                    .setIsSmartLockEnabled(true)
                                    .setProviders(Arrays.asList(
                                            new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
                                    .build(), RC_SIGN_IN
                            );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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