android - 当应用程序被杀死时无法获取 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'
);
解决方案
推荐阅读
- typescript - 如何将 react javascript 转换为类型脚本?
- c++ - 请解释这个语句(cout << 1 + int((a < b) ^ ((b - a) & 1)) << endl)
- r - 如何用R中的两个指数项拟合曲线
- r - 在图例中为 R 中的 ggplot 格式化日期
- java - 如何安装STS来蚀氧(2018.march) 市场上没有sts?
- stm32 - STM32Cube IDE 相同的代码最终运行或出现硬故障...俄罗斯轮盘赌
- amazon-ecs - ECS 代理端口有哪些?
- if-statement - 如何在modelica的if语句中使用Multiple And运算符?
- jquery - 如何从 Firestore 中的过滤文档中获取子集合中的数据
- xcode - 如何在 UIWebView / WebKit 中编写单元测试用例 (XCTest) - Swift