注册令牌

在应用程序首次启动时,FCM SDK 会为客户端应用程序实例生成注册令牌。
如果要定位单个设备或创建设备组,则需要通过扩展 FirebaseInstanceIdService 来访问此令牌。

生成新令牌时会触发 onTokenRefresh 回调,你可以使用方法 FirebaseInstanceID.getToken() 来检索当前令牌。

例:

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

   /**
     * 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 onTokenRefresh() {
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

    }

}