I have used GCM to get push notifications, now if I Force stop the app from the settings on the Android device, will it be able to get push notifications?
I have read many posts that say in this case an app cannot receive notifications.
Is there any possibility to get notifications?
Once you force-stop your app from Settings, your code will not run until something manually runs one of your components (ie the user manually launches an activity).
Therefore after force-stopping your app from Settings, you will not receive GCM messages.
If you want to get notifications you have to manually restart your app.
This is by design since Android 3.1.
Apps that are in the stopped state do not receive broadcast Intents.
Stopped state is:
when the app is initially installed (before the user runs something in
the app) or
after a Force Stop.
You can find more about this here: http://developer.android.com/about/versions/android-3.1.html#launchcontrols
Related
Users might close my application by swiping them from recent apps because they are used to that. In those cases, users don't get notifications about important events and they are complaining about this. How can I restart a force-closed app so that it will continue to receive FCM messages?
FCM messages are supposed to be received in background. A notification should be shown in the device's tray even if you application is not running / suspended.
I'm testing Firebase Push notifications, sending a notification from the Firebase composer panel, and I noticed that if I close the app process from App Information panel, the push notifications sent doesn't reach the device. Even if I start again the app the notification is lost and is never received.
I also tryed this:
close the app process -> shut down the device -> power on the device -> send a notification... and the notification is not received!
It seems that firebase can only receive notifications if the device has the app started and not 100% closed, I mean, closing it just with back key but not killing the app process.
How is this possible? It is supossed that firebase should receive notifications even with the app closed.
I'm testing on a Nexus 5X with Android 8.0 and I'm using the last version of Firebase push Notifications.
Sorry for the late, but hope this help next users that will have this problem because there is no answer selected as "Solution".
When setup correctly the service, this will work even the app is closed. That because, Firebase Messages travel by Google Play Services so closing your app doesn't have a relation with the service.
At first, notification never came. By searching in the device settings I saw that the energy saving system for my app was active (when closed was removed from stack) so notification was sent but my app couldn't take and display these.
After disabling that option, I've test many time and I found that sometimes notification come with a late of 2-3 minutes when app is completely closed. Sometimes it touch the 5 minutes. You need to be patient and it will come!
Instead, When app is opened or closed simply by back button, notification come in few seconds.
In your AndroidManifest.xml file remove android:exported=false from your Messaging service.
Explanation: When your app is completely killed or removed from back stack. OS tries to restart the messaging service but if there is android:exported=false in your manifest file then OS will not able to restart the service because such service can only be restarted by the same app.
Reference: https://developer.android.com/guide/topics/manifest/service-element#exported
It seems that firebase can only receive notifications if the device
has the app started and not 100% closed, I mean, closing it just with
back key but not killing the app process.
No, FCMs are sent to all the devices that have Google Play services and the targeted application. That is why it is called Push Notifications.
Your application also get notifications when it is running, to handle those you need to override
onMessageRecieved(RemoteMessage mes);
There could be many reasons for the app not getting notifications. Some of them could be :
Messaging Services not included in the Manifest
Play services not configured correctly. Or not present in the Phone.
Sometimes Latency is High (rarely). I noticed it sometimes take take about 2-3 minutes
after composing.
SHA1 fingerprint not registered in Console and/or updated google-services.json not present in sources.
Uninstall and reinstall the app. So that token Regeneration may take place.
Please follow this link to get started with messaging.
https://firebase.google.com/docs/cloud-messaging/android/client
Have you added firebase services on Java code?
Here is the link: firebase/quickstart-android
You have to add those 3 java file in java folder and also add those service name in AndroidManifest.xml
if you are sending it from your firebase console it sends a notification message so those you will not get if your app is closed, you need to send messages that have the data payload which the console does not do.
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
Took this screenshot from Firebase documentation, seems its not possible with FCM
I'm guessing this is a really rookie question, so I'm hoping someone can steer me in the right direction quickly & easily.
I have an app that receives GCM messages. The code that contains the GcmListenerService-derived class is located within my app. Because of this, the user MUST run my app after starting their phone in order for my listener to start listening (verified by restarting my phone, sending a test from Postman, and NOT getting the message / notification until I launch my app).
Do I need to create some type of service or something that will allow my app to get new GCM messages, even after restarting the phone (and not launching the app)?
Thanks!
Yes. You will need a broadcast receiver which listens on the BOOT_COMPLETED broadcast message and launches the push notification service. However, you still have to start the app once to register the receiver. It will also not work if the user force quit the app. There are some approaches, which also will restart the app automatically if the user killed the app, but I think it is a bad practice. In some circumstances the user wants to stop the app and keep it closed.
When none of the activity is launched even once,i want to send a push notification to the user.
For example, once user installs application but doesnt open then a notification is pushed that please use the application.
Please help me with the code.
You can't. How would the user call the registration process for the push messages if he never ran the app itself? Until he does, the app is considered to be in a stopped state and you can't interact with it unless you have another app installed that would "start" it.
You can start a background service on application level and registering on gcm server and other process so even if app is not used you can send notification as your service has registered your device with gcm id on your server.Call api for registering device to your server from your GCMIntentService class.
I have used GCM to get push notifications, now if I Force stop the app from the settings on the Android device, will it be able to get push notifications without restart application...
No. If the user force-stops your app, they are indicating that they do not want your app to run again, for any reason, until they manually launch it again. Your objective is to give the user no reason to force-stop your app. Note that I do mean "force-stop" (i.e., press the "Force Stop" button from Settings) -- ordinary task managers, or swiping from the Recent Tasks list in Android 4.x, does not have this effect.