FCM for android: popup system notification when ap

2019-02-23 19:15发布

Is it possible to show popup for firebase system notification (when app is in background) on the top of screen? I use setPriority(Notification.PRIORITY_MAX) for this to show notifications from onMessageReceived in foreground.

I use both notification and data fields, so I don't have access to received notification in foreground. I've tried setting priority to high and using notification-only pushes - nothing helps.

2条回答
对你真心纯属浪费
2楼-- · 2019-02-23 19:57

If you sent data field only in notification, you can handle notification inside the below function

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " +remoteMessage.getNotification().getBody());
    }

}

Please note that don't include notification field in that request

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-23 20:09

It is only possible to handle the message in onMessageReceived when your app is in background when using a data only payload.

When using both notification and data in your payload, the expected behavior is that the Android System will handle the notification when the app is in background, regardless of what is the value of your priority.

See the official docs on Handling Android Messages for more details.

查看更多
登录 后发表回答