it doesn't expire tho. it renews itself if one of the following happens.
它不会过期。如果发生下列情况之一,它会自行更新。
-The app deletes Instance ID
- 该应用删除实例ID
-The app is restored on a new device
- 该应用程序在新设备上恢复
-The user uninstalls/reinstall the app
- 用户卸载/重新安装应用程序
-The user clears app data.
- 用户清除应用数据。
Monitor token generation
监控令牌生成
The onTokenRefreshcallback fires whenever a new token is generated, so calling getToken in its context ensures that you are accessing a current, available registration token. Make sure you have added the service to your manifest, then call getToken in the context of onTokenRefresh, and log the value as shown:
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// 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(refreshedToken);
}