Android 为什么来自FCM的remoteMessage在后台不工作?
当我从服务器发送消息时,仅当应用程序在前台运行时才起作用。 我发送带有有效负载和通知正文的消息。 如果应用程序在后台运行,则不会调用onMessageReceived。 什么会失败 我的代码n清单Android 为什么来自FCM的remoteMessage在后台不工作?,android,firebase,firebase-cloud-messaging,Android,Firebase,Firebase Cloud Messaging,当我从服务器发送消息时,仅当应用程序在前台运行时才起作用。 我发送带有有效负载和通知正文的消息。 如果应用程序在后台运行,则不会调用onMessageReceived。 什么会失败 我的代码n清单 <application android:largeHeap="true" android:allowBackup="true" android:icon="@mipmap/ic_launcher
<application
android:largeHeap="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:usesCleartextTraffic="true">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/logo_mediano" />
<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"/>
<service
android:name=".mackey.FCMService"
android:enabled="true"
android:directBootAware="true"
android:exported="false"
android:resource="@drawable/ic_menu_camera">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</aplication>
<uses-permission android:name="android.permission.INTERNET" />
渐变模块应用程序
implementation 'com.google.firebase:firebase-messaging:20.2.3'
背景中的Logcat:
V/FA: Connecting to remote service
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 1
I/FirebaseMessaging: Starting download of: https://image.freepik.com/vector-gratis/imagen-tridimensional-coche-taxi-aislado-fondo-blanco_53876-12108.jpg
W/FirebaseMessaging: Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used.
V/FA: Inactivity, disconnecting from the service
前景中的Logcat:
I/System.out: remote message
D/android-fcm: NOTIFICATION
D/android-fcm: new Notification
D/android-fcm: DATA
D/android-fcm: Title php : data php
D/android-fcm: Title php : default
当应用程序位于后台时,在用户点击与推送消息关联的通知之前,不会调用onMessageReceived。 如果希望系统调用onMessageReceived而不让用户点击通知,请尝试发送静默推送消息
I/System.out: remote message
D/android-fcm: NOTIFICATION
D/android-fcm: new Notification
D/android-fcm: DATA
D/android-fcm: Title php : data php
D/android-fcm: Title php : default