当应用处于后台或关闭状态时,Android 10手机中不会发生FCM通知。
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.e("FCM", "onMessageReceived");
if (new Helper(this).isLoggedIn()) {
Intent intent = new Intent(this, FirebaseChatService.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, pendingIntent);
Log.e("FCM", "scheduled");
}
}
}