首页 > 解决方案 > 当应用程序被杀死时无法获取 FCM 通知android

问题描述

当应用程序在os version > Oreo (8)中被杀死时,我试图获取 FCM 通知,但是当应用程序被杀死时我面临一个问题,我无法接收任何 FCM 通知..但是当应用程序在后台打开时我我得到了它们,但在应用程序被杀死时无法正常工作。

依赖项:

implementation platform('com.google.firebase:firebase-bom:27.1.0')
implementation 'com.google.firebase:firebase-messaging'
classpath 'com.google.gms:google-services:4.3.5'

显现:

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

   <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_stat_ic_notification" />
  
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id" />

这是使用 PHP 发送的有效载荷

有效载荷

$server_key = FCM_SERVER_KEY;
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$fields =  array(
    'to' => $token,
    'priority' => 'high',
    'notification' => array(
        'title' => $title,
        'body' => $message,
        'sound'=> true
    ),
    'data' => array(
        'sec_id' => $mainScreen,
        'sec' => $subScreen,
        'extra'=> $extra,
        'msg_type'=> $msg_type
    )
)

;
  
$headers = array(
    'Authorization:key=' . $server_key,
    'Content-Type:application/json;charset=utf-8'
);

标签: androidfirebase-cloud-messaging

解决方案


推荐阅读