Android Question push notifications when app is not runing ?

Tomas Petrus

Active Member
Licensed User
Longtime User
I have implemented push notifications and its working when the app is in background or foreground even when it is softkilled by swiping.

But when you go to the app settings and FORCE APP to shutdown or you restart the phone.

Then notifications are not working.

Any solution ?

thanks
 

drgottjr

Expert
Licensed User
Longtime User
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
I have implemented push notifications and its working when the app is in background or foreground even when it is softkilled by swiping.

But when you go to the app settings and FORCE APP to shutdown or you restart the phone.

Then notifications are not working.

Any solution ?

thanks
check if you applied notification permission
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
permission revised,
FirebaseMessaging reciever - used one from the example setted in manifest to start on boot + permission

Now it seems to be working and recieving notification always.. Just last question thou.. Can the reciever be killed by the OS or not ?
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
After some testing yes, reciever is killed by OS after some time when the phone is locked and app not used..
So it should be handled by something like:

B4X:
StartServiceAtExact(FirebaseMessaging, DateTime.Now + 30 * DateTime.TicksPerSecond, True)
??

Can reciever schedule to restart itself ?
or it should be handled in Main ?
is Main started automaticaly when reciever is started on boot ?

Thanks for clarification
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
Thanks, but I don't understand : (
I have checked B4J sender from example FCMPush and I don't see anything special inside .. From what I can see it just send message by POST in JSON format to https://fcm.googleapis.com ...

I have 40+apps some in 5 projects in firebase..
Notification need to be send when relevant event happen in backend C# API. So I will have to have multiple B4J senders ?
Also the production enviroment runs in hybrid cloud linux-windows docker containers + some native windows without docker as backups.
So I would need to distribute multiple senders accross the enviroment and somehow call them externaly from API.
It seems really complicated and time consuming in comparison with sending notifications directly by API ...

Notification are send to the topic or to the individual device - for example: "Your car is coming in 5 minutes."

When sending notifications directly from API I have 2 problems in Android reciever devices:
  • messages coming when the app is on the background doesn't have icon
  • and FirebaseMessaging reciever is geting killed by OS in some point when the app is not running
I don't understand how B4J Sender is handling these issues ?
  • I have examined the nuget I am using and it seems that it is doing exactly same thing like B4J..
    B4X:
    HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/v1/projects/" + settings.ProjectId + "/messages:send");
Please explain ...
Thank you
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
After analyzing B4J sender and read everything about push meesages on the forum I came to following conslusions.
  • HIGH priority - seems to solve a lot of things - more testing needed but delivery is now much more better, even in sleeping states etc.
  • B4J sender example is not correct according to actual Google/firebase API documentation
    • B4J Sender for Android messages incorporate only data {title, body}
      • this part is intended for cases, when the app is handling the notification - intended for time when app is in foreground
        • icons working
        • What is not working is when app is killed - swiped or device rebooted and app not started - then there is no notification
      • To handle this you have to use notification {title, body} object, then all cases (app not running, app on background) are recieving this part
        • and this is the case when there is no notification icon just white square
If u don't believe me it is all explained here: https://firebase.google.com/docs/cloud-messaging/concept-options#notifications
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
Problem with icon also solved add to the manifest

CORRECT
B4X:
AddApplicationText(
<meta-data
android:name = "com.google.firebase.messaging.default_notification_icon"
    android:resource = "@drawable/notification" />
)

WRONG
in some documentation and forums there it was described like this but this is incorect it has to be android:resource not android:icon
B4X:
AddApplicationText(
<meta-data
android:name = "com.google.firebase.messaging.default_notification_icon"
    android:icon= "@drawable/notification" />
)
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
And last thing.. Is there any way to know if the notification was delivered ?
  • when app is on the foreground - and notification is handled by
    B4X:
    Sub fm_MessageArrived (Message As RemoteMessage)
    then ok I can add in data part field with notificationId and then save to DB that it was delivered
  • but when app is on background or not runnig and notification is handled by OS then I dont know..the state...
    • reason for this is that we are now handling important messages by SMS. I want to minimalize SMS usage and switch to notifications... but when notification is not delivered, I would like to send SMS as backup/insurance that the client get the information...
    • is there any way ?
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
Studied all the documentation and it seems now there is no way to know.
Through API you can get some aggregate delivery reports but not reports on individual messages
 
Upvote 0
Top