当应用程序被用户或 Android 操作系统停止或终止时,Android 应用程序未收到 Firebase 通知

标签 android firebase firebase-cloud-messaging xmpp gsm

<分区>

当我的 android 应用程序被终止时,我的 android 应用程序没有收到任何 firebase 通知,FirebaseMessagingService 在我关闭应用程序时被操作系统终止。当应用程序位于前台或后台时,一切正常。当应用程序在后台并且我发送一条数据消息时,它被我的 FirebaseMessagingService 中的 onMessageReceived() 接收(有趣的是,它是为每条消息创建然后销毁的,即 FirebaseMessagingService). 当我终止应用程序(通过从打开的应用程序列表中滑动)时,onMessageReceived() 中不再收到消息。所有服务都被杀死! 谁能帮帮我吗?提前致谢!

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <!-- DefaultOrderedBroadcastReceiver will start this service to send notifications to system tray -->
        <service
            android:name=".fcm.SystemTrayNotificationsSenderIntentService"
            android:enabled="true"
            android:exported="false" />

        <!-- the FCM receiver service -->
        <service
            android:name=".fcm.FCMNotificationReceiverService"
            android:exported="true"
            android:stopWithTask="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

<service
       android:name=".fcm.chat.FCMChatOfflineMessagesNotificationJobSchedulerService"
            android:exported="false"
            android:permission="android.permission.BIND_JOB_SERVICE" />

最佳答案

根据 Firebase Documentation ,它声明如果从服务器端,您只发送 notification 对象,当您的应用程序位于前台时,它将调用 onMessageReceived() 函数,并将显示在系统/通知托盘(如果应用程序进入后台)。

如果您在同一通知中同时发送notificationdata 对象,它将在前台调用onMessageReceived() 函数,当应用程序将在后台运行,它将在托盘中显示通知和 data 对象,只有当您点击通知并移动到您指定的 Intent 时,您才会获得。

现在,当您只发送data 对象时,app 每次都会调用onMessageReceived() 函数。

所以如果你想每次都执行onMessageReceived(),只从你的服务器端发送data对象。

关于当应用程序被用户或 Android 操作系统停止或终止时,Android 应用程序未收到 Firebase 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53986051/

相关文章:

node.js - 未收到 Firebase 云消息传递收据

未收到带有 Firebase 云消息传递的 Android 后台通知

android - 将 google-play-services 库导入 Intellij IDEA 12(和 13)

java - 具有自定义 View 的旋转动画

firebase - Firebase Cloud Functions 如何确认 Cloud pub/sub

android - 尝试几次后退出 Firebase

angularjs - angularfire2:未启用 Cloud Firestore API

firebase - react-native-firebase_messaging 未在 project.ext .'react-native' .versions.android.compileSdk 中定义默认值

android - 非根设备 (Android L) 上的设备所有者,没有 NFC,使用 adb shell,dpm set-device-owner

android - 简单的 css 媒体查询不起作用