註冊令牌

在應用程式首次啟動時,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);

    }

}