5 ms·
This is usually done by sending a push message with no content, that just prompts the app to fetch messages whenever new ones are available. Of course, if the A
by TobTobXX 4y ago
This is usually done by sending a push message with no content, that just prompts the app to fetch messages whenever new ones are available. Of course, if the App then proceeds to post the message contents to a notification in plaintext, well then... But you can adjust the settings for what to display in the notif and of course just disable the notifications, so no other app will be able to listen.
- psnehanshu 4y agoFor that the app must be in foreground. How does WhatsApp manage to be always on the foreground? My app always gets killed by Android.
- pas 4y agoby having a permanent/persistent notification. for example KeePass2Android does it pretty well. (usually when the battery saver kicks in it kills these semi-foreground things.) when the phone starts the user has to first start the app though (and I found this to be true for Signal, Skype and probably for WhatsApp too)
- psnehanshu 4y agoWhatsApp doesn't have a persistent notification though. > when the phone starts the user has to first start the app though Just tested this and this is not the case with WhatsApp. I am on a Samsung and I am not sure if WhatsApp get's any special treatment.
- pas 4y agoah, I probably misunderstood the context. KeePass2Android does this to prevent Android from putting it to "sleep", which leads to the in-memory unlocked DB getting unloaded.
- self 4y agoOn Android, push notifications are handled by a service defined in your application's manifest. The system launches the service when a notification is received, and calls its onMessageReceived() function which you customize to display the notification's layout, add actions to tap events, etc. https://firebase.google.com/docs/cloud-messaging/android/receive https://firebase.google.com/docs/cloud-messaging/android/rec...
- psnehanshu 4y agoApparantly `onMessageReceived()` is called only when the app is in foreground.
- Larrikin 4y agoI spent a day of my life at work over this annoying confusion. https://firebase.google.com/docs/cloud-messaging/android/receive https://firebase.google.com/docs/cloud-messaging/android/rec... It is counterintuitive, feels arbitrary, and logical thinking will cause you to misread the chart they provide. Whether that method is called is based on the payload of the notification as well as making sure you've properly registered the types of notifications. This is helpfully spread between Android docs and the Firebase docs. The exact differences between the notifications that will trigger this (while still being compatible with iOS) is left as an exercise to the reader.
- tadfisher 4y agoIt's not that bad if you completely ignore Firebase and override onHandleIntent. Now you can choose what to do with the message without caring about the difference between "data" and "notification" messages or whether your app is in the foreground.
- pas 4y agoCan you elaborate on this a bit? Is it possible to use a non-Firebase push notification service on Android, that properly works in the background? Our the app still needs to use FCM but you can override the client-side handler somehow?