Android 应用程序未运行时,不在状态栏上显示推送通知(Firebase云消息)
在AndroidManifest.xml中Android 应用程序未运行时,不在状态栏上显示推送通知(Firebase云消息),android,firebase-cloud-messaging,Android,Firebase Cloud Messaging,在AndroidManifest.xml中 <service android:name=".CustomFirebaseInstanceIDService" android:exported="true"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_
<service
android:name=".CustomFirebaseInstanceIDService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name=".CustomFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
因此:
onMessageReceived
成功调用和成功在状态栏(顶部)中显示推送通知(标题和正文)
onMessageReceived
成功调用和成功在状态栏(顶部)中显示推送通知
import firebase_admin, sys
from firebase_admin import credentials, messaging
message = messaging.Message(
data={
"title": "Test data",
"body": "Body of long test text of data test long body message for type data"
},
token=sys.argv[1],
)
response = messaging.send(message)
另外,如果我从Firebase控制台发送消息,则当应用程序未运行时,成功显示状态栏上的推送通知。尝试仅发送
数据有效负载(无通知有效负载),它应始终调用onMessageReceived
。还可以尝试添加优先级(my.js示例):
没有帮助。仅发送数据时不调用MessageReceived我已使用示例负载更新了答案。我觉得你的舱单已经很好了。
object PushNotificationService {
val TAG = PushNotificationService::class.java.name
val CHANNEL_ID = "channelId"
val NOTIFICATON_ID = 1
fun showNotification(context: Context, title: String, body: String) {
val intent = Intent(context, SignInActivity::class.java).apply {
this.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val pendingIntent: PendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
val builder = NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher))
.setContentTitle(title)
.setStyle(NotificationCompat.BigTextStyle().bigText(body))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Set the intent that will fire when the user taps the notification
.setContentIntent(pendingIntent)
.setAutoCancel(true)
// Show the notification
with(NotificationManagerCompat.from(context), {
// NOTIFICATON_ID is a unique int for each notification that you must define
this.notify(NOTIFICATON_ID, builder.build())
})
}
import firebase_admin, sys
from firebase_admin import credentials, messaging
message = messaging.Message(
data={
"title": "Test data",
"body": "Body of long test text of data test long body message for type data"
},
token=sys.argv[1],
)
response = messaging.send(message)
const payload = {
data: {
title: 'finalTitle',
body: 'message',
},
android:{
priority: 'high'
},
topic: channel
};
admin.messaging().send(payload)