简体   繁体   English

推送通知不会在 Android 上弹出

[英]Push notification doesn't pop up on Android

I am creating flutter application using FCM for sending push notifications.我正在使用 FCM 创建 flutter 应用程序来发送推送通知。 I am sending notifications with Cloud Functions from website by sending JSON to device.我通过将 JSON 发送到设备来从网站发送带有 Cloud Functions 的通知。 This however works perfectly on iOS (notification pops up) on Android I get sound and notification only appears in status bar.然而,这在 Android 上的 iOS(通知弹出)上完美运行,我听到声音并且通知仅出现在状态栏中。 Any advice on how to make it pop up?关于如何让它弹出的任何建议?

This is the JSON I am sending:这是我发送的 JSON:

{
    "message":{
        "token" : result,
        "notification" : {
            "body" : body,
            "title" : title,
        },
        "data": {
            "body": body,
            "title": title
        },
        "apns": {
            "headers": {
                'apns-priority': '10',
            },
            "payload": {
                "aps": {
                    "sound": 'default',
                }
            },
        },
        "android": {
            "priority": 'high',
            "notification": {
                "sound": 'default',
            }
        },
    }
}

You are correctly setting "priority": "high", but I think this might be the case that FCM lowers the priority.您正确设置了“优先级”:“高”,但我认为这可能是 FCM 降低优先级的情况。 This is from the FCM Documentation :这来自FCM 文档

High priority messages generally should result in user interaction with your app or its notifications.高优先级消息通常会导致用户与您的应用或其通知进行交互。 If FCM detects a pattern in which they don't, your messages may be de-prioritized.如果 FCM 检测到他们没有检测到的模式,您的消息可能会被取消优先级。

If your app is on the foreground, you can achieve desired behaviour if you set NotificationChannel priority and also notification priority in the NotificationBuilder to high priority.如果您的应用程序在前台,您可以通过将 NotificationChannel 优先级和 NotificationBuilder 中的通知优先级设置为高优先级来实现所需的行为。 If the app is on the foreground the notification is created by your extended FirebaseMessagingService and priority can be set.如果应用程序位于前台,则通知由扩展的 FirebaseMessagingService 创建,并且可以设置优先级。

But if the app is on the background or closed, notification is created by the notification tray by the system.但是,如果应用程序处于后台或关闭状态,系统会通过通知托盘创建通知。

This applies if you send both notification and data object.这适用于同时发送notificationdata object 的情况。

Possible solution is to send only data object (without notification object).可能的解决方案是仅发送data object(没有notification对象)。 Like this, the notification is always created by the FirebaseMessagingService.像这样,通知总是由 FirebaseMessagingService 创建。 Whether the app is on the foreground or in the background or closed.应用程序是在前台还是在后台或关闭。 See this table this table看这个表这个表

Add this line to your Notification Builder Channel:将此行添加到您的 Notification Builder 频道:

channel.setShowBadge(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM