【问题标题】:Android app not receiving Firebase Notification when app is stopped or killed by user or android OS [duplicate]当应用程序被用户或android操作系统停止或杀死时,Android应用程序没有收到Firebase通知[重复]
【发布时间】:2019-05-27 21:41:08
【问题描述】:

当我的 android 应用程序被杀死时,我的 android 应用程序没有收到任何 firebase 通知,FirebaseMessagingService 在我关闭应用程序时被操作系统杀死。当应用程序位于前台或后台时,一切正常。当应用程序在后台并且我发送一条数据消息时,onMessageReceived() 在我的FirebaseMessagingService 中接收到它(有趣的是,它是为每条消息创建然后销毁的,即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" />

【问题讨论】:

  • 你是奥利奥还是以上?
  • 您在AndroidManifest.xml 中注册了BroadcastReceiver 吗?
  • @IshitaSinha 是奥利奥!!
  • @ReazMurshed 是的,一切正常,当应用程序关闭或 FirebaseMessagingServices 被杀死时出现问题,它只是不再收到通知了!!

标签: android firebase firebase-cloud-messaging xmpp gsm


【解决方案1】:

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

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

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

因此,如果您想每次都执行onMessageReceived(),请仅从您的服务器端发送data 对象。

【讨论】:

  • 这正是我所做的,服务器端总是发送数据对象并且从不使用通知有效负载,服务在清单中完美注册但是当应用程序进入后台时,从打开的应用程序列表中滑动或杀死通知从未到达,我认为FCM服务本身被android应用程序管理器或其他东西杀死了......这个问题发生在android OREO上!你知道其他解决方案吗!
  • 您能否在定义服务的地方发布您的AndroidManifest 代码?
  • 你在build.gradle中使用的是哪个版本的firebase-messaging
  • 我更新了上面的任务并添加了清单代码,是的,我正在使用最新版本的 firebase-messaging 实现“com.google.firebase:firebase-messaging:17.3.4”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-01
  • 1970-01-01
相关资源
最近更新 更多