Android Question Firebase notifications during sleep

Discussion in 'Android Questions' started by marcick, May 6, 2019.

  1. marcick

    marcick Well-Known Member Licensed User

    Many customers are telling me this issue, so I think it is related to some "battery optimization" features in recents Android versions because everything was working fine before.
    After a couple of minutes the device is in sleep, it does not receive Firebase notifications. As soon it is waked up, then it shows (I mean notifications are not lost, but just not displayed during sleep).
    If I put the device in sleep again it can receive notifications, but after a couple of minutes it stops.
    I did another test:
    Send a notification to the device (in sleep) and nothing happens.
    Send another notification. Nothing happen.
    Send a gmail to the device. It wakes up, show the two notification and gmail notification also.

    Just for these tests, I'm using the B4J tool to send notification ( a bit adapted to my needings but the core should be the same)

    Any ideas ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Try it with this in the B4J code:
    Code:
    m.Put("android", CreateMap("priority""high"))
     
  3. marcick

    marcick Well-Known Member Licensed User

    It does not work ....
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that there is anything else that you can do. Your app only starts once the OS delivers the message.
     
  5. marcick

    marcick Well-Known Member Licensed User

    But how all other apps do ? WhatsApp, mail, etc
    How can be useful a notification if it does not notify you an event ?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    This is a known fact that some manufacturers whitelist popular apps.
     
  7. marcick

    marcick Well-Known Member Licensed User

    So we can stop tu use Firebase notifications because they will not work when you need they work ?
    I'm confused. Possible there isn't any solution ?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    You can do the best you can.
    Implement it correctly and it will work on most devices.
     
  9. marcick

    marcick Well-Known Member Licensed User

    Sorry Erel: I have a very popular Samsung S8 with Android 9 and it does not work.
    What should I do to implement it correctly ?
    Do you mean that if it does not work it's sure there is an error in my code ? (i would hope so)
     
  10. DonManfred

    DonManfred Expert Licensed User

    I have a Samsung Note 8 with Android 9 and it does work.
     
  11. marcick

    marcick Well-Known Member Licensed User

    Do you live it a copule of minutes in sleep and it is able to receive firebase notification ?
    Would be a good news.
    I'll put togheter a sample app and see.
     
  12. Erel

    Erel Administrator Staff Member Licensed User

  13. marcick

    marcick Well-Known Member Licensed User

    Ok guys, I've put togheter the B4J sample app to send notification and the B4A sample App too.
    Find them attached.
    To run all you need to

    1) declare proper apikey in the B4A app
    2) set the correct package name of B4A app and register in the firebase console.
    3) download the proper google-services.json file an put in the B4A app folder.

    Testing on a Samsung S8 Android 9

    As soon as you put the device in sleep, you can receive notifications, but if you wait a couple of minutes not (they are "buffered". You will receive them when the device wakes up for other reasons)

    I do hope I'm doing something of wrong.
     

    Attached Files:

  14. marcick

    marcick Well-Known Member Licensed User

    Looks like the problem is described here, but I have no deep knowledge to understand what to do
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    This is not related as the B4J code always sends data messages.

    I don't think that you are doing anything wrong. You will see that the messages do eventually arrive. Try to click on the notification whenever it comes. Newer versions of Android are more sophisticated and can apply all kinds of heuristics to decide when to wake up the device.
     
  16. marcick

    marcick Well-Known Member Licensed User

    Thanks Erel but .... I must find a solution.
    In my case also a 1 minute delay in notification cause big troubles.
    And there is no chances to convince my customers with any arguments because other apps does not have this problem.
     
  17. Jorge M A

    Jorge M A Active Member Licensed User

  18. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    FWIW - I find that my Pixel (running Pie) has similar issues. I haven't really kept track of the details, but it seems that some notifications don't show up until I wake the phone up, but others do.

    I just put it down to yet another restriction in Pie due to Android's ever increasing desire to improve battery life.

    - Colin.
     
  19. marcick

    marcick Well-Known Member Licensed User

    There was a time ... my app was structured with background services that had cyclic connections with my server (every 15 sec) to sync data and give instant local notifications when an event occoured.
    Then had become more difficult to maintain background services running and not be killed by OS, so I moved to remote notification structure.
    That had worked great. Just for a while ....
    I can't understand. There must be a solution to have a realtime alarm when an event occour at server side.
    I have the same app for IOS also and notifications work perfect. And who is more severe than Apple in put limitations to developers ?
     
  20. marcick

    marcick Well-Known Member Licensed User

    I'm reading a lot on internet, search for "Android notification delay" and you will see tons of threads of people struggling for this issue.
    Yes, the problem is related to battery optimiziation and DOZE mode, introduced in the lasts Android versions.
    You fill find a lot of hints on how to disable this feature but (in my case) they don't work. This is a good place where everything is well summarized, if you want to give it a try.

    Definitely, you must disable DOZE mode if you want instant notifications as before, but the only method that seems to work is through ADB (and need to be repeated everytime you restart the device). If you want to try, follow here (you can revert back without problems then). I've just tried and it works perfect, but I can't say if it has an impact on battery life (I suppose yes).
    There is also a 5$ app on PlayStore to easily disable DOZE mode, I didn't try it yet.

    I'm disappointed: if you navigate in settings menù there are all the options to disable doze (also for specific apps only), to allow data in background etc. But they simply has no effect. How is it possible ? I understand the goal for a manufacturer is to maximize battery life, but why don' give the user the option to choose what to do ?
    In our days (and in my opinion) instant notifications are mandatory. What fucking notification is if you are informed of a motion detection, an alarm, a simple message also, after 5 minutes ?
     
    rboeck, peacemaker and Jorge M A like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice