2

大家好,我使用firebase从服务器接收推送通知。当应用程序运行时一切正常。我收到了通知,我会处理它并通过通知托盘显示它。看起来很完美。这是我的代码。应用程序关闭时的Firebase通知(问题)

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(); 
     } 


    }} 

清单代码。

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

。问题在于应用程序关闭时。没有这个类的日志作品,什么都没有。但这里有一个有趣的部分。我可以从服务器看到整个JSON,并显示在通知托盘上(显示整个JSON对象)。真的没有得到我的代码中的错误。检查图像。 1-成功案例。 enter image description here

2-未知问题的情况下enter image description here

回答

0

对不起已故的答复我已经找到了解决方案,如果任何人有问题与it.Here是从火力文档。 消息类型

随着FCM,您可以发送两种消息给客户:“显示信息

通知消息,有时认为是 Data messages,被处理由客户端应用程序。 通知消息包含一组预定义的用户可见密钥。相比之下,数据消息仅包含自定义键值对。 通知消息可以包含用户点击通知时发送的可选数据有效内容。

使用场景
Notification消息 FCM自动显示给最终用户代表客户端应用程序的设备的消息。通知消息具有预定义的一组用户可见密钥和可选的自定义键值对的数据有效载荷。

如何发送 在可信环境如云功能或你的应用服务器,使用Admin SDK或HTTP和XMPP的API:设置通知的关键。可能有可选数据有效载荷。始终可折叠。 使用通知作曲器:输入消息文本,标题等并发送。通过提供自定义数据添加可选数据有效载荷始终可折叠。

使用场景

数据消息客户端应用程序负责处理数据消息。数据消息只有自定义的键值对。 在受信任的环境中,例如Cloud Functions或您的应用服务器,请使用Admin SDK或HTTP和XMPP API:仅设置数据密钥。可以是可折叠的也可以是不可折叠的。

Link

0

从这个link,我想消息应该包含两个通知和数据有效载荷。

或者,也许你可以在消息的优先级设置为高这样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" 
    } 
} 
相关问题