何时创建 fcm 刷新令牌

When do fcm refresh tokens created(何时创建 fcm 刷新令牌)
本文介绍了何时创建 fcm 刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 android 新手,现在正在寻找 firebase.在我的应用程序中可以登录多个手机号码.所以我正在做的是删除当前令牌

I'm new to android and now looking on firebase.In my app multiple mobile numbers can be logged in. So what am doing is deleting current token by

FirebaseInstanceId.getInstance().deleteInstanceId();

然后当我用新号码登录时,就会生成新的令牌.

and after that when I log in with new number, then new token gets generated.

所以我的问题是哪个事件触发了令牌再生事件.上面代码行的另一件事是我必须在线程(除了主线程)上运行才能工作

So my question in this exactly which event triggers token regeneration event. One more thing that above code line should I have to run on thread (other than MAIN THREAD) to work

推荐答案

这是我用来获取firebase令牌的服务

This is the service which I used for getting firebase token

    public class FCMInstanceIDListenerService extends FirebaseInstanceIdService {
AppSharedPreferences appSharedPreferences;
    @Override
    public void onCreate() {
        super.onCreate();
        String CurrentToken = FirebaseInstanceId.getInstance().getToken();
        if (CurrentToken!=null){
            Intent intent = new Intent("device_id");
            LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
            Log.d("token", "Refreshed token: " + CurrentToken);
            appSharedPreferences.putString("device_id",CurrentToken);
        }
        else {
               onTokenRefresh();
                }
       }

    public FCMInstanceIDListenerService() {

        appSharedPreferences=AppSharedPreferences.getsharedprefInstance(this);
        // prefManager = PrefManager.getInstance(this);
    }

    @Override
    public void onTokenRefresh() {
        super.onTokenRefresh();
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Intent intent = new Intent("device_id");
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
        Log.d("token", "Refreshed token: " + refreshedToken);
        appSharedPreferences.putString("device_id",refreshedToken);
        // prefManager.putString(PrefrenceConstants.KEY_DEVICE_ID, refreshedToken);

    }

}

来自 开发者网站:

onTokenRefresh() 当系统确定令牌需要刷新.应用程序应该调用 getToken() 并发送所有应用服务器的令牌.

onTokenRefresh() Called when the system determines that the tokens need to be refreshed. The application should call getToken() and send the tokens to all application servers.

这个不会被频繁调用,key轮换需要用到并处理由于以下原因导致的实例 ID 更改:

This will not be called very frequently, it is needed for key rotation and to handle Instance ID changes due to:

  • 应用删除实例 ID

  • App deletes Instance ID

应用在新设备上恢复

用户卸载/重新安装应用

User uninstalls/reinstall the app

用户清除应用数据

系统将限制所有设备的刷新事件以避免使用令牌更新重载应用程序服务器.

The system will throttle the refresh event across all devices to avoid overloading application servers with token updates.

这篇关于何时创建 fcm 刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)