Search code examples
androidfirebase-cloud-messagingandroid-8.0-oreoandroid-8.1-oreooneplusthree

FirebaseMessagingService is not working in background using one plus 3 android oreo 8.0


Firebase onMessageReceived never called when app is not running and removed from recent apps list. I'm working with Firebase and sending data payload notifications to my app from my server, i have tried to use JobScheduler to start MyFirebaseMessagingService every 1 minute in case the system is killing my service but this approach didn't work for me on One Plus 3. I know that android add limitation on background services to optimize battery usage, but does this limitation affect on FCM service?

here is my message string:

{
"notification": {
    "title": "Hello",
    "body": "Notification",
    "badge": 1,
    "icon": "app_icon",
    "color": "#ffffff",
    "sound": "default",
    "clickAction": "home",
    "tag": "parent_ccid_6"
},
"message": {
    "priority": "high",
    "type": "daily_tips",
    "data": {
        "parent_ccid": "parent_ccid_6",
        "id": "2",
        "sound": "default"
    }
},

}

and here is my Service in manifest

 <service
        android:name=".util.FCM.MyFirebaseMessagingService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

Solution

  • I didn't find any solution to solve this issue by code. The only way to revive notification is to go to settings and select "Don't optimize" from Battery optimization settings, and it works fine in background, otherwise notification handler will not be triggered. I faced this issue with all installed applications on One plus 3.