相关疑难解决方法(0)

如何在Firebase中的后台应用时处理通知

这是我的清单

    <service android:name=".fcm.PshycoFirebaseMessagingServices">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service android:name=".fcm.PshycoFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
Run Code Online (Sandbox Code Playgroud)

当应用程序处于后台并且通知到达时,默认通知将会运行并且不会运行我的代码onMessageReceived.

这是我的onMessageReceived代码.如果我的应用程序在前台运行,而不是在后台应用程序时,则调用此方法.如何在应用程序处于后台时运行此代码?

// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // If the application is in the foreground handle both data and notification messages here.
    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

379
推荐指数
17
解决办法
31万
查看次数

Firebase消息 - 在后台应用时创建单挑显示

使用FCM,当应用程序处于后台或未运行时,我会在系统托盘中收到推送通知.当应用程序在前台时,我可以覆盖onMessageReceived并创建我自己的抬头通知NotificationCompat.

当我的应用程序在后台运行或未运行时,有没有办法创建提醒通知?

谢谢

编辑:这里的参考是我通过curl使用的消息有效负载https://fcm.googleapis.com/fcm/send

{
  "to":"push-token",
    "content_available": true,
    "priority": "high",
    "notification": {
      "title": "Test",
      "body": "Mary sent you a message!",
      "sound": "default"
    },
    "data": {
      "message": "Mary sent you a Message!",
      "notificationKey":"userID/notification_type",
      "priority": "high",
      "sound": "default"
    }
}
Run Code Online (Sandbox Code Playgroud)

android android-notifications heads-up-notifications firebase-cloud-messaging

9
推荐指数
2
解决办法
6708
查看次数