Custom Notifications when app is in background or killed
Hi,
I'd like to implement custom notification styles when app is in background or is killed. Is there a Firebase broadcast receiver class one could extend to implement the same? Would be very helpful. Thanks.
A notification is sent but does not reach all devices. 70% - 80%.
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'priority' => 'high',
'data' => array("notification" => true),
);
@jaydip5500 data message payload is 4 KB only. Difficult to send an image. Maybe you could send an URL used by your application to get the image from your server.
@tariqul000 @yerca Do you respect the limit of 1000 notifiactions sent at a time, then the exponential delay between 2 successive requests?
@2ndGAB Yes I do. I send 500 notifications every 1 minute, to not load my server.
an example of response.
{"multicast_id":xxxxxxxxxxxxxxxx,"success":500,"failure":0,"....
Ok good, no more idea.... sorry
@yerca Have you linked FCM with the Play Store console? You can check the FCM Statistics to see if there were errors sending to devices. Maybe the messages were queued/stored?
@2ndGAB @efung Thanks. I've looked. Many messages are in state accepted but not confirmed.
I have solved this problem.
In some devices, when the app is in background or killed,it really has this problem,but some devices not,maybe it has some relation with the android version or google play services version.
If you use the GCM api to send the notification ,the ic_launcher icon can be showed well.
If you use the Firebase Console to send the notification, your ic_launcher need to make some modification, the background must be transparent, just like the picture below.
Firebase will give a better solution and coming up very soon.

@abdymalikmulky modify your ic_launcher just like what I do
sorry... but imho, modify icon/logo design just for bug in library is a unacceptable workaround... I could tolerate an alternative default file name instead ic_launcher
Update the version to the least ,current is 9.8.0, than follow the solution below, https://firebase.google.com/docs/cloud-messaging/android/receive
finally ! thanks @chenyucheng97
@JulienDev @chenyucheng97 please tell the version you used for resolving this issue.
hi,i have the same problem. When app is killed,my app can not receive notification?i want to know why and how to solve that?
Hi!
I'm having the same issue... However, Is it possible to show the notification when the App is launched?
Thanks in advance
@PaoloApplingua yes its possible, you can try create and call notification manager notify same as you call notification from FCM
Couldn't agree more. One year passed and it's still not possible to control background notification and/or send data messages via the console unfortunately.
Meanwhile, people seem to get around the issue with hacky workarounds overwriting undocumented functions in FirebaseMessagingService like so:
https://stackoverflow.com/questions/37325051/notification-icon-with-the-new-firebase-cloud-messaging-system
Only thing that seems to work so far, but I'd rather refrain from that. Otherwise, why wouldn't it be mentioned in the docs.
shinayser commented on Jul 14, 2016 Just want to leave my feedback about the notification framework:We as developers should have full control of the notifications. I never wanted FCM to auto-notify my system bar for me and i should ALWAYS receive the "onMessageReceived" callback, doesn't matter in foreground or background. Pehaps we could have a checkbox on the Firebase Notification console indicating "Auto-notify". If unchecked, we get the "onMessageReceived" callback. Otherwise, it notifies the system bar.
I have the same problem.
Application mode background or killed at that time FCM not call "onMessageReceived".
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
// Called when message is received.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
}
I have really weird and frustrated problem, and I have no idea why it is happening. I have application signed and published as closed beta release on Google Play store. I have installed it on my phone and sending push message with data payload from my Digital Ocean droplet, works on my Huawei P9 Lite Android 7 even when application is killed, onMessageRecieved is always activated, but on the other phone Huawei P8 Lite, no notification is received, only when application is in foreground and in background (not killed)
So I have created this application to try and figure out what is happening: https://github.com/clzola/firebase-test (you will find php directory in which you can find scripts I use to send messages)
So here are the steps:
- Run application
- Copy token
- Kill application
- $ php notification.php "token"
on my phone, notification is shown in tray (Huawei P9 Lite, Android OS 7)
On the other phone (Huawei P8 Lite, Android OS 6), same steps reproduced, no notification in tray
I have tried to send only data payload, same scenario on p9 lite works, on p8 lite does not work, also tried with sending both payloads, notification and data payload, same thing, on p9 lite works on p8 lite does not.
When application is running on p8 lite (app is in foreground) sending messages with notification payload only, data payload only and both payloads works, also if I click back button and application goes to background also works all three type of messages. Now I swipe off application (killing it), none of the above messages are received on p8 lite. I have also tried to sign apk, send it to my email, detach phone from lap top (Android Studio), restart phone, and then installed signed apk, opened application, read the token, kill application and send notification payload only message and there is no notification in tray...
As I understand, Google Play Service should receive this notification message payload and show it in tray when application is not running ....
I noticed this message in logcat, it is printed out each time I send message to my phone when application is not running:
08-18 19:17:41.602 4565-4565/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=clzola.com.firebasetest (has extras) }
Also sending from Firebase Console I get same results
EDIT: I have figured out what was the problem, Huawei's EMUI has this Protected Apps system, and there I found both of my applications and switch that was off, I put switched on and both applications works on P8. Next question is why on my Huawei P9 Lite phone, they were switched on automatically with my interaction ... however I have found two Xiaomi phones that have same scenario but cannot find option similar to Protected Apps...
I couldn't believe that this was not possible. It is not clear from the docs that you can only modify the notification when the app is in foreground and it also is not logical. I understand that there is a possibility to let Firebase handle this, but you should be able to override this. The "data message" is not a good solution because iOS will not show the notification anymore.
I like the way I can handle the notification when the app is in the foreground, so if that would also be possible in the background, that would be great and also way more logical.
In the meantime is there anything I can do to make this work on iOS and Android? On Android I want to show my own custom notification (which can open in different activities, have a different priority, different styles and different notification tags). This custom notification currently only works in the foreground. Also I want iOS to stay the same (show the notification when push message is received and when opened same custom tasks like on Android). Currently the only possible solution I see is to send a "data message" to all Android users on a specific topic and the "notification message" to all iOS users on a specific topic.
Please tell me there is another way to do this. Because this is just horrible...