相关疑难解决方法(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
查看次数

未收到Firebase Cloud Messaging的Android后台通知

当应用程序处于后台或关闭时,我已经搜索了很多关于通知的信息.我顺便使用Firebase云消息传递.它对我不起作用.我已经使用了Android设置,当应用程序位于前台或手机未锁定时,会收到通知.

  • 安装后,令牌会正确打印并订阅该主题.
  • 当应用程序在前台处于活动状态时发送通知(因此屏幕已解锁并显示应用程序),我会收到通知和标题,如下所述onMessageReceived.
  • 当我在应用程序未显示但仍在最近的应用程序中并且屏幕已解锁时发送通知时,我会收到包含标题和消息的通知notification payload.
  • 当我在应用程序未显示但仍在最近的应用程序中并且屏幕被锁定时发送通知时,不会收到任何内容.
  • 当应用程序被关闭并从最近的应用程序中删除时,我发送通知时,不会收到任何内容.

如何更改此设置,以便即使关闭或手机被锁定,应用也会始终收到通知?

PS.我阅读了有关受保护应用程序的打盹模式,即使我将我的应用程序与受保护的应用程序放在一起我什么也得不到.我正在测试华为P8 Lite.

AndroidManifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity android:name=".activities.MainActivity"
        android:configChanges="orientation"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service
        android:name=".services.MyAppFirebaseMessagingService"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>
    <service
        android:name=".services.FirebaseIDService"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action …
Run Code Online (Sandbox Code Playgroud)

android android-notifications firebase firebase-cloud-messaging

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