cancel
Showing results for 
Search instead for 
Did you mean: 

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

raffinkira
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member320731
Discoverer
0 Kudos

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.

former_member320731
Discoverer
0 Kudos

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\"}"
}

raffinkira
Participant
0 Kudos

I think the JSON string is sent to mobile service platform, which maybe different from Firebase.

Currently, the URL I post was:

lv_url = 'https://xxx.hanatrial.ondemand.com/restnotification/registration/d479ae156dd42f921fda7edbbfe81a34'.
lv_url = 'https://xxx.hanatrial.ondemand.com/restnotification/application/com.sap.ming13/user'.