Skip to Content

BroadcastReceiver.onReceive( ) is not invoked when app is in background.

Hi all,

I am developing notification function for Android device.

The following code is handling notification payload from Firebase and was generated by wizard.


However, when the app is running in background and notification payload has property "sound", for example:

{"alert":"Dear Customer", "data":"Notification", "sound":"default"}, the above method onReceive( ) won't be invoked.

I can still see a notification but only with app name, without alert and app icon, and this is different from a normal notification. Currently, I have to remove the property "sound" and it's working.

Anyone knows anything about this?


Regards,

Ming

onre.png (174.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Mar 26 at 05:56 PM

    Here it looks like the server is sending the notification as Notification-Message. The notification should be a Data-Notification. (Ref https://firebase.google.com/docs/cloud-messaging/concept-options )

    To send a Data notification, please use the format below.

    {

    "alert": "TravelAgencies",
    "data": "{\"message\": \"Notification to all devices registered to application\", \"sound\": \"default\"}"
    }

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 28 at 03:57 PM

    Yes, that is correct the JSO send is to the mobile services. If you send the JSON I suggested above to the same URL(endpoint), it will send a data message to the device.

    Add comment
    10|10000 characters needed characters exceeded