我尝试多次重新安装我的应用程序,我注意到调用onTokenRefresh()的次数大约是4次(日志输出)
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken);
}
}
是否有任何方法可以保证调用 onTokenRefresh(),以便在有良好的互联网连接时,应用程序将订阅主题,例如启动每次都检查的服务是否应用程序已订阅主题,如果没有,则重新启动firebase服务。
在onCreate()函数中我做了:
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// checking for type intent filter
if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
// gcm successfully registered
// now subscribe to `global` topic to receive app wide notifications
FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
} else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) {
// new push notification is received
}
}
};
答案 0 :(得分:0)