Android Question A little confused about Push Notifications

FrostCodes

Active Member
Licensed User
Hello everyone, I have over 25k users I want to send push notifications to using FCM. I have implemented the example made by Erel and have been using it for some time now but I was very curious about something so I add my analytics tracking code to the event of when a new notification arrives. I noticed that even though in the past 30 days I have more than 6k active users, only about 490 received my push notifications. I thought this is weird as the example in the forum said that it would work both in foreground and background mode which I tested it but today I decided to sit down and test it with multiple phones, I tested it with android 7, 8 and I noticed that I only receive it when

1) The app is open currently
2) Or when I minimized or pressed the back button and the app is still in my recently open android app list.

I don't know if this is normal or not but my aim with push notifications was even if you just turned on your phone or haven't opened my app in a long time I can use it to make you remember about my app so I did something; I made a service that uses StartServiceAt() and auto-starts every 1 hour with the Firebase code :


B4X:
CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")

and then I retested my app in release mode again and I quit it and even cleared the recently used app list and I pushed a notification with @Erel Fcm sending tool and the notification works perfectly well even without my app been opened at all.

So I am confused is something wrong with my first code or its normal and for what I want, it's better I use the second code to achieve it.
Thanks!

EDIT:

The first code I meant is EREL example .. here
and the second code is just the example but I added a new service that uses StartServiceAt to call the sub below every 1 hour
B4X:
CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
 
Last edited:

FrostCodes

Active Member
Licensed User
Hi I do use the B4j code to send the messages but what I am saying is my users phones don't receive it unless...

1) the app is opened when I just sent a notification
2) or they recently opened the app maybe less than 1 or 2 ago... Which means the app is probably still minimized or hasn't been killed by the os..

The issue is I used all your code samples and it's the same behavior... So I don't know why this behavior when I send it and the app isn't in use they just don't receive any notification.
 
Upvote 0

davemorris

Active Member
Licensed User
HI
We have used notifications as a form of communications on Apps for years. It don't matter what you do, the phones appear to go into a "deep sleep" if unused. We have tried all types of tricks to keep them responding to notifications - either by FCM or Sockets using TCP, and frankly none work if the phone is left alone and the screen locks. Don't get fooled its OK initially, then over a period of about 5 minutes the phone takes longer to respond until it eventually stops responding altogether.

Its a simple test to prove this problem simply ping (using FCM) the phone under test from another phone (which must be kept alive) and write a small bit of code for the phone under test which will return a message to the other phone which displays the response time.

We done this test with a Web Server but the end result is always the same (it eventually stops communicating).

However, best of luck - if the find a solution please post.

Kind regards
Dave Morris
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
You are describing a different problem.

Push notifications should work, whether the app is running or not. The best way to test it is by restarting the phone, wait a minute or two and send a notification. Do it while the phone is not sleeping and of course connected to the internet.

It is true that there are cases where the message will not arrive immediately when a phone is sleeping. Sending with high priority does help a bit.
 
Upvote 0

FrostCodes

Active Member
Licensed User
This means that something is misconfigured. You can reboot the device and push notifications will work. The app must be compiled in release mode.
Hi, I have done this multiple times.. in fact, at one point I started thinking it was my phone that had the issue.. i then borrowed 10 phones with different android versions from my friend and tested the example on them... it was the same issue!
 
Upvote 0

FrostCodes

Active Member
Licensed User
HI
We have used notifications as a form of communications on Apps for years. It don't matter what you do, the phones appear to go into a "deep sleep" if unused. We have tried all types of tricks to keep them responding to notifications - either by FCM or Sockets using TCP, and frankly none work if the phone is left alone and the screen locks. Don't get fooled its OK initially, then over a period of about 5 minutes the phone takes longer to respond until it eventually stops responding altogether.

Its a simple test to prove this problem simply ping (using FCM) the phone under test from another phone (which must be kept alive) and write a small bit of code for the phone under test which will return a message to the other phone which displays the response time.

We done this test with a Web Server but the end result is always the same (it eventually stops communicating).

However, best of luck - if the find a solution please post.

Kind regards
Dave Morris


Hi yes this is similar to how I built my analytics to test and it failed also! I would post my solution once I am done with testing it out on multiple devices for a few days. :)
 
Upvote 0

FrostCodes

Active Member
Licensed User
You are describing a different problem.

Push notifications should work, whether the app is running or not. The best way to test it is by restarting the phone, wait a minute or two and send a notification. Do it while the phone is not sleeping and of course connected to the internet.

It is true that there are cases where the message will not arrive immediately when a phone is sleeping. Sending with high priority does help a bit.
Hi I also did test it with high priority in the firebase REST API request.. In fact in the notification code on b4a i also tested it with change the importance level to high but still the same issue... :(
 
Upvote 0

FrostCodes

Active Member
Licensed User
Which type of message are you sending? Check the energy saving options for the app, too (some manufacturers set it to "strict" for unnown apps)
Hi, thanks. I am sending normal text messages exactly the type in Erel b4j Sending tool. My app energy saving is disabled as I also did research and checked if that was the issue.. In fact, I checked that I didn't disable notification by mistake because Tik tok that I haven't used in over 4 months plus still sends me notification almost every day or so and I just didn't understand why my own app can't do this.
I would attach a screenshot of what I am saying
 

Attachments

  • 1630267082725.png
    1630267082725.png
    177.4 KB · Views: 32
  • 1630267115617.png
    1630267115617.png
    154.3 KB · Views: 31
Last edited:
Upvote 0

FrostCodes

Active Member
Licensed User
In fact, for my app I created multiple group chats on WhatsApp because I suspected the push notification was not working... so I asked them if they do receive the push notifications... See their response so you can see that it's really a big problem for me.
These is just some of the responses, the few that said they received it said they had recently opened the app or were currently using it

1630267545076.png
 
Last edited:
Upvote 0

Sandman

Well-Known Member
Licensed User
Tik tok that I haven't used in over 4 months plus still sends me notification almost every day or so
That's interesting. I wonder if you've noticed a pattern in their notifications? Like, for instance, if they tend to arrive at roughly the same time every day? Or perhaps at the same(ish) minute every hour? That might indicate that they launch a timed service that wakes the app to help deliverability.
 
Upvote 0

FrostCodes

Active Member
Licensed User
That's interesting. I wonder if you've noticed a pattern in their notifications? Like, for instance, if they tend to arrive at roughly the same time every day? Or perhaps at the same(ish) minute every hour? That might indicate that they launch a timed service that wakes the app to help deliverability.
Thanks! This is exactly what I said I tested in my first post and I was told that is the wrong way to do it... I checked the services list in the android running service list and I noticed a pattern with FB and even Gmail also
 
Last edited:
Upvote 0

Mashiane

Expert
Licensed User
Please when you have done all your tests and have a working solution for this, please hit me up, I could use it as in yesterday because it's a big deal with our clients.

The sad reality is that it makes one look incompetent whislt the receipt of the notifications is a major part of what we are doing.

At least there is a consensus that messages at times do not get received and a solution for that is of utmost importance.

Thanks.
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
I don't want to be negative :)
yes, something changed. testing using the b4j demo, the phone is not always receiving the pushs any more like last year for example, but it works nice when sending push notifications from firebase console.
In fact, last time playing with the push notifications for my Takeaways-App the phone received the push from B4J-demo the next day (some push notifications online),
then I was thinking ohh! maybe I just sent too many push notifications from b4j-demo, maybe :p
 
Last edited:
Upvote 0

KMatle

Expert
Licensed User
Best option is to send data messages only with high priority (throw an own notification then). In the app option (long click the icon) set energy saving to "none". Works for me. Search the forum or the Google docs for the options.
 
Upvote 0

Sandman

Well-Known Member
Licensed User
This is exactly what I said I tested in my first post
Yeah, I saw that. But what I wrote was about how the other apps do it. I mean, if there's a time-based pattern like that in Tik Tok one could interpret it to mean "we couldn't get it to work unless we use a timer to wake up", which would be interesting also.
 
Upvote 0
Top