问题
I have app which during lunch create anonymous user ID, but after UN-install my app create new user with new ID. How can I get userID which was before UN-install ?
My code to anonymous login:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mAuth = FirebaseAuth.getInstance();
if(mAuth.getCurrentUser() == null){
createUser();
}else{
user = mAuth.getCurrentUser();
}
}
public void createUser() {
mAuth.signInAnonymously().addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Log.d("TAG", "signIn: succes");
}else{
Log.w("TAG", "signIn: fail");
}
}
});
}
回答1:
You can use Firebase Authentication to create and use only temporary anonymous accounts to authenticate with Firebase. Anonymous authentication
accounts don't persist across application uninstalls. When an application is uninstalled, everything that was saved locally will be deleted, including the anonymous auth token that identifies that account. Unfortunatelly, there is no easy way to reclaim that token for the user.
Instead, you should encourage all your users to fully log in with a supported account provider (Google
, Fabcebook
, Twitter
and so on) so that they can log in from all their devices without worry of losing their data.
回答2:
Store id in SharedPreferences before app uninstall.
来源:https://stackoverflow.com/questions/47136603/after-uninstall-app-creating-new-user-insted-of-get-userid-from-firebase