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

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

问题描述

我的应用程序在启动时创建了匿名用户 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 进行身份验证.匿名身份验证 帐户不会在应用程序卸载后持续存在.卸载应用程序时,本地保存的所有内容都将被删除,包括标识该帐户的匿名身份验证令牌.不幸的是,没有简单的方法可以为用户收回该令牌.

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 获取用户 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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