简体   繁体   English

应用程序关闭时发出的Firebase通知(问题)

[英]Firebase Notification when application is close (Issue)

everybody, I m using firebase to receive a push notification from the server. 大家,我正在使用Firebase从服务器接收推送通知。 Everything working fine when the application is running. 当应用程序运行时,一切正常。 I got the notification, I handle it and show it over notification tray. 我收到了通知,我将其处理并显示在通知托盘上。 Seems perfect. 看起来很完美。 Here is my code. 这是我的代码。

public class FirebasePushService extends FirebaseMessagingService {
    private static final String TAG = "FireBase main service ";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "Got Message: " + remoteMessage.getFrom());
        try {
            if (remoteMessage != null && remoteMessage.getNotification() != null
                    && remoteMessage.getNotification().getBody() != null) {
                String body = remoteMessage.getNotification().getBody();

                Log.d(TAG, "From: " + remoteMessage.getFrom());
                Log.d(TAG, "Notification Message Body: " + body );

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }


    }}

Manifest code. 清单代码。

 <service android:name="app.asparagus.com.asparagus.firebase.FirebasePushService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

. The issue is when the application is closed. 问题是关闭应用程序时。 No log works of this class, nothing. 没有此类的日志作品,什么也没有。 But here is the interesting part. 但这是有趣的部分。 I can see the whole JSON from the server, and it is shown on notification tray ( whole JSON object is displayed). 我可以从服务器看到整个JSON,它显示在通知托盘上(显示整个JSON对象)。 Really not getting what's wrong in my code. 确实没有弄明白我的代码出了什么问题。 Check the image. 检查图像。 1- The success case. 1-成功案例。 在此处输入图片说明

2- Unknown issue case 2-未知案件 在此处输入图片说明

From this link , I think the message should contain both notification and data payload. 通过此链接 ,我认为该消息应同时包含通知和数据有效负载。

Or maybe you can set the priority of the message to high like this one 或者,也许你可以在消息的优先级设置为高这样一个

{
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
  "priority" : "high",
  "notification" : {
    "body" : "This week's edition is now available.",
    "title" : "NewsMagazine.com",
    "icon" : "new"
  },
  "data" : {
    "volume" : "3.21.15",
    "contents" : "http://www.news-magazine.com/world-week/21659772"
  }
}

Sorry for late reply I have found the solution and In case anyone else have issue with it.Here is from firebase documentation. 对不起,我很晚才答复,我已经找到了解决方案,以防万一其他人有问题。这来自firebase文档。 Message types 讯息类型

With FCM, you can send two types of messages to clients: 使用FCM,您可以向客户端发送两种类型的消息:

Notification messages , sometimes thought of as " display messages. " Data messages , which are handled by the client app. 通知消息 ,有时被称为“ 显示消息”。 Data messages ,由客户端应用程序处理。 Notification messages contain a predefined set of user-visible keys. 通知消息包含一组预定义的用户可见键。 Data messages , by contrast, contain only custom key-value pairs. 相反, 数据消息仅包含自定义键值对。 Notification messages can contain an optional data payload that is delivered when users tap on the notification. 通知消息可以包含一个可选的数据有效载荷,当用户点击通知时会传递该有效载荷。

Use scenario 使用场景
Notification message FCM automatically displays the message to end-user devices on behalf of the client app. 通知消息 FCM代表客户端应用程序自动将消息显示给最终用户设备。 Notification messages have a predefined set of user-visible keys and an optional data payload of custom key-value pairs. 通知消息具有一组预定义的用户可见键和一个自定义键值对的可选数据有效载荷。

How to Send In a trusted environment such as Cloud Functions or your app server, use the Admin SDK or the HTTP and XMPP APIs: Set the notification key. 如何发送在受信任的环境(如Cloud Functions或您的应用服务器)中,使用Admin SDK或HTTP和XMPP API:设置通知密钥。 May have optional data payload. 可能具有可选的数据有效负载。 Always collapsible. 始终可折叠。 Use the Notifications composer : Enter the Message Text, Title, etc., and send. 使用Notifications作曲家 :输入消息文本,标题等,然后发送。 Add optional data payload by providing Custom data. 通过提供自定义数据来添加可选的数据有效负载。 Always collapsible. 始终可折叠。

Use scenario 使用场景

Data message Client app is responsible for processing data messages. 数据消息客户端应用程序负责处理数据消息。 Data messages have only custom key-value pairs. 数据消息仅具有自定义键值对。 In a trusted environment such as Cloud Functions or your app server, use the Admin SDK or the HTTP and XMPP APIs: Set the data key only. 在Cloud Functions或您的应用服务器之类的受信任环境中,请使用Admin SDK或HTTP和XMPP API:仅设置数据密钥。 Can be either collapsible or non-collapsible. 可以是可折叠的或不可折叠的。

Link 链接

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

相关问题 单击通知时如何关闭我的应用程序? - How to close my application when clicking on a notification? 应用程序启动时关闭android通知 - Close android notification when application starts 当应用程序退出并强制关闭时,Firebase通知图标和铃声无效。 它仅在Lollipop版本设备上方发生 - Firebase Notification Icon and Ringtone is not working when application gets logout and force close. It Occurs only above Lollipop version device 应用程序运行时不显示Firebase通知 - Firebase Notification Does Not Show When Application Run 应用启动时的Android Firebase通知 - Android Firebase notification when application starts 应用程序关闭或最小化时需要打开 Notification.java 活动 - Need to open Notification.java activity when application close or minimize Firebase 通知问题 - Firebase Notification issue 应用程序被杀时,Android Firebase Push通知无效 - Android Firebase Push notification not working when application is killed 在后台向Android应用程序接收Firebase通知时会发生什么? - What happens when a Firebase notification is recieved in the background to an Android application? 当我单击默认Firebase通知Android 6.0.1时,应用程序未启动 - Application is not launching when i click on default firebase notification, Android 6.0.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM