Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
amberkira opened this issue Feb 26, 2019 · 4 comments
Closed

Comments

@amberkira
Copy link

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
@samtstern
Copy link
Contributor

@amberkira sorry about my slow response here. I appreciate that this isn't working for you, but there's no evidence here to suggest that it's anything different than what's going on in the many other FCM issues on this repo.

Sometimes there's nothing we can do, device manufacturers optimize their OS in a way that makes it impossible to push notifications to backgrounded or killed apps. We are always looking for ways to improve this.

@mtali
Copy link

mtali commented Mar 29, 2020

How does other application i.e WhatsApp or Facebook solve this?

@frozenade
Copy link

How does other application i.e WhatsApp or Facebook solve this?

I'm wondering too

@EjilolaHammedEjitomiwa
Copy link

some apps are given special access to the device resources.
Like Whatsapp, phone messages etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants