卸载应用程序后,从Firebase创建新用户以获取userID [英] After uninstall app creating new user insted of get userID from Firebase

查看:57
本文介绍了卸载应用程序后,从Firebase创建新用户以获取userID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用,该应用在启动过程中会创建匿名用户ID,但在卸载之后,我的应用会使用新ID创建新用户.如何获得卸载之前的用户ID ?

I have app which during launch create anonymous user ID, but after uninstall my app create new user with new ID. How can I get userID which was before uninstall ?

我的匿名登录代码:

 @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");
                }
            }
        });

    }

推荐答案

您可以使用Firebase身份验证来创建和使用临时的匿名帐户来通过Firebase进行身份验证. Anonymous authentication帐户不会在应用程序卸载期间持续存在.卸载应用程序后,将删除本地保存的所有内容,包括标识该帐户的匿名身份验证令牌. 不幸的是,没有简单的方法可以为用户收回该令牌.

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.

相反,您应该鼓励所有用户使用受支持的帐户提供商(GoogleFabcebookTwitter等)完全登录,以便他们可以从所有设备登录而不必担心丢失他们的数据.

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.

这篇关于卸载应用程序后,从Firebase创建新用户以获取userID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆