9

The phone is OnePlus3T. The oxygen OS build is 4.1.6. App receives notification when the app is in foreground on in background but in the memory. But does not receive notification when the app is not in memory i.e. swiped out of the memory. The notification is received on other devices having android OS verions 4.2, 5.1.1, 6.0.1, 7.1.1 Lineage OS even the app is not in the memory.

Kindly suggest something. Thanks in advance.

Rajas47Ashtikar
  • 583
  • 2
  • 6
  • 11
  • if its working on other devices, then it sounds like its something that manufacturer changed in the OS so I doubt there is anything you will be able to do about it. – tyczj Jun 30 '17 at 13:40
  • But then notifications for Whatsapp and Gmail are working.....I have a service for creating notifications apart from FirebaseMessagingService. It is START_NOT_STICKY. Tried START_STICKY, but still did not work. Am I doing something wrong? – Rajas47Ashtikar Jun 30 '17 at 14:08
  • See my answer [here](https://stackoverflow.com/a/39505298/4625829) – AL. Jul 01 '17 at 01:51
  • 1
    Possible duplicate of [Android app not receiving Firebase Notification when app is stopped from multi-task tray](https://stackoverflow.com/questions/39504805/android-app-not-receiving-firebase-notification-when-app-is-stopped-from-multi-t) – Thomas Aug 22 '17 at 09:48

2 Answers2

24

I also faced the same issue.

Two ways to solve this issue

1- Using notification payload

notification payload can be send using data tag or notification tag.

using data tag

 "data" {
  "title": "welcome",
  "description" :"to your app" ,
  "image" :"image_url",  
  "deeplink" :"deeplink",
   - -
  }

it will trigger the FirebaseMessagingService onMessageReceived method. it will not work on some devices, when an app is in the background.

using notification

 "notification" {
   "title":"title",
   "description" : "description",
   "click_action" :"activity to be open"
   ..
}

this is handled android system try and show the notification, this case onMessageReceived method of your FirebaseMessagingService will not call.notification will be shown even app is in the background. one disadvantage of this is - you can't the customize notification because it's handled by the Android system. more info

2- Enable Auto start in device setting

when you send notification using data and app is killed notification will not be shown. if you observe the log cat you will see

W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.cabipool (has extras) }

can be solved in oneplus 3 setting -->Apps --> click on gear wheel -->last option App select app auto launch --> find your app enable the switch

this the problem in most of the devices like Vivo,Oppo,xiaomi,Asus, one plus 3.

steps to enable app auto launch very based on device manufacturer.

Update:

OnePlus 3 and Android 8.0 the Auto-start option was removed, so now you can go to Settings> Battery> Battery Optimisation> (Three dots menu on the left-top corner) Advanced optimization> Turn off Advanced Optimization.

Rahul Devanavar
  • 3,917
  • 4
  • 32
  • 61
  • 8
    On OnePlus 3 and Android 8.0 the Auto-start option was removed, so now you can go to Settings> Battery> Battery Optimisation> (Three dots menu on left-top corner) Advanced optimisation > Turn off Advanced optimisation. – Isaac Bosca Jan 18 '18 at 11:30
  • notification or data which payload is compulsory calling FirebaseMessagingService class onMessageReceived() method? can you please tell me,i too have same issue in some devices? @Rahul Devanavar – Revathi Manoharan Feb 15 '18 at 13:04
  • @RevathiManoharan if you send the notification from firebase dashboard by default it will be notification payload. you have to use curl or to send the custom data payload.notification payload has limitations it only supports title and description. – Rahul Devanavar Feb 16 '18 at 06:04
2

This looks like a problem of the specific device.

To check run this command while your app is closed (after a reboot or after swiping)

adb shell dumpsys package MY-PACKAGE | grep stopped

if you can read stopped=true it means that the manufacturer of your device implemented a non standard behavior consisting in "force-stopping" applications when they are swiped.

force-stopping is very similar to disabling the app until the user opens it again.
When the app is in that state many other Android API will not work! (broadcasts, alarms..)

If this is the problem, please please contact the manufacturer and request that they fix the device!

Diego Giorgini
  • 12,489
  • 1
  • 47
  • 50
  • Thank you for the reply, I tried the command, and stopped = false. Yet the notifications do not appear – Rajas47Ashtikar Jul 04 '17 at 10:44
  • 2
    It could be that the device has a different type of customization. If the app works on different devices it means that the code is correct. – Diego Giorgini Jul 04 '17 at 11:41
  • i think its depend on package name when i test my package name stopped=true and when i add whatsapp package name stopped = false, if you have any idea please let me know i'm facing same issue. – Sanjay Aug 28 '18 at 10:24