首页 > 解决方案 > 当所有应用程序都备份到新手机时,FCM 令牌不会更新

问题描述

恢复备份数据后,我希望onTokenRefresh调用该方法,但事实并非如此。相反,当我第一次运行应用程序时,会调用该方法。

由于更新后的token无法在推送服务器上更新,因此新手机收不到FCM通知。

onTokenRefresh备份应用程序时有没有办法强制?或者,是否有应用程序安装回调?

标签: androidfirebasefirebase-cloud-messaging

解决方案


onTokenRefresh()现在已弃用

您需要覆盖新方法 onNewToken()

/**
 * Called if InstanceID token is updated. This may occur if the security of
 * the previous token had been compromised. Note that this is called when the InstanceID token
 * is initially generated so this is where you would retrieve the token.
 */
@Override
public void onNewToken(String token) {
    Log.d(TAG, "Refreshed token: " + token);

    // If you want to send messages to this application instance or
    // manage this apps subscriptions on the server side, send the
    // Instance ID token to your app server.
    sendRegistrationToServer(token);
}

推荐阅读