Skip to content

FCM hasn't received any Message when app is closed on Android Oreo or Above #816

@amberkira

Description

@amberkira

Step 1: Describe your environment

  • Android device: XIAOMI MIX2S_and XIAOMI 8
  • Android OS version: ___android P and Android 8.1 __
  • Google Play Services version: 4.2.0_
  • Firebase/Play Services SDK version: firebase core 16.0.7 & messaging 17.3.4_

Step 2: Describe the problem:

   Goal: APP shows Notifications after FCM send message. 
   Problem: when app is closed , the app never received messages from FCM that happens on Devices with Android Oreo or above.

Steps to reproduce:




Observed Results:

  • What happened? This could be a description, logcat output, etc.

Expected Results:

  • What did you expect to happen?

Relevant Code:


  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
      super.onMessageReceived(remoteMessage);
      Context context = MainApplication.getContext();
      NotificationManager localNotificationManager = (NotificationManager)context.getSystemService("notification");

      Intent localIntent1 = new Intent(context, PreLoadActivity.class);
      localIntent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
      PendingIntent localPendingIntent = PendingIntent.getActivity(context, 0, localIntent1, PendingIntent.FLAG_CANCEL_CURRENT );

      String msg = context.getResources().getString(R.string.notification_content);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
          Notification.Builder builder = new Notification.Builder(getApplicationContext(), "com.hellochinese.message")
                  .setContentTitle(context.getResources().getString(R.string.notification_title))
                  .setSmallIcon(R.drawable.app_icon)
                  .setContentIntent(localPendingIntent)
                  .setContentText(msg);
          NotificationChannel channel = new NotificationChannel("com.hellochinese.message", context.getString(R.string.app_name), NotificationManager.IMPORTANCE_MIN);
          channel.enableVibration(false);

          localNotificationManager.createNotificationChannel(channel);
          Notification notification = builder.build();
          localNotificationManager.notify(0, notification);

      }else {
          NotificationCompat.Builder alamNotificationBuilder = new NotificationCompat.Builder(
                  context).setContentTitle(context.getResources().getString(R.string.notification_title)).setSmallIcon(R.drawable.app_icon)
                  .setContentText(msg)
                  .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                  .setContentIntent(localPendingIntent);

          Notification notification = alamNotificationBuilder.build();

          notification.defaults = Notification.DEFAULT_VIBRATE;
          localNotificationManager.notify(0, notification);
      }
  }

Message Json  Format:
{
"message":{
  "token":"dqQtpg3C6So:APA91bH6X-Kq3lk7-P7-bpqchGsZFRicmG12LFa7nd_V-Ol5paJrVmnsLOSxy-0g5lghJ3qKVcLVupenxpV7pFUHegtkZnJQrFPsU3_j2iTaPP9VBAaqVgxjY31aXpuwwa1O0CdeUj7q",
  "notification":{
    "title":"Portugal vs. Denmark",
    "body":"great match!"
  },
  "data" : {
    "Nick" : "Mariyyo",
    "Room" : "PortugalVSDenmark"
  },
},

 "to" : "dqQtpg3C6So:APA91bH6X-Kq3lk7-P7-bpqchGsZFRicmG12LFa7nd_V-Ol5paJrVmnsLOSxy-0g5lghJ3qKVcLVupenxpV7pFUHegtkZnJQrFPsU3_j2iTaPP9VBAaqVgxjY31aXpuwwa1O0CdeUj7q"
}

Http Url:
POST: https://fcm.googleapis.com/fcm/send

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions