@@ -32,7 +32,27 @@ public class PushMessageReceiver extends FirebaseMessagingService {
startService(intent);
}
} catch (IllegalStateException e) {
- Log.e(Config.LOGTAG,"PushMessageReceiver is not allowed to start service");
+ Log.e(Config.LOGTAG,"PushMessageReceiver is not allowed to start service after receiving message");
+ }
+ }
+
+ @Override
+ public void onNewToken(String token) {
+ if (!EventReceiver.hasEnabledAccounts(this)) {
+ Log.d(Config.LOGTAG,"PushMessageReceiver ignored new token because no accounts are enabled");
+ return;
+ }
+ final Intent intent = new Intent(this, XmppConnectionService.class);
+ intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH);
+ try {
+ if (Compatibility.runsAndTargetsTwentySix(this)) {
+ intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true);
+ ContextCompat.startForegroundService(this, intent);
+ } else {
+ startService(intent);
+ }
+ } catch (IllegalStateException e) {
+ Log.e(Config.LOGTAG,"PushMessageReceiver is not allowed to start service after receiving new token");
}
}