Push Notifications not received when the App is force-stopped - android

The Push Notifications are received fine when the App is closed by navigating back or when closed from Recent Apps.
But when the App is force-stopped from Settings, then the App doesn't receive the Push Notifications. I don't know if it is a limitation of the platform or I'm missing something.
How to change the App to receive Push Notification even if force-stopped?

Read this post please! It's possible that you uses a simple broadcast receiver then broadcast receiver don't guarantee the service is working always finally if you want to have service works all time you need to use WakefulBroadcastReceiver class.
-- Edited 2 hours later --
This is not limitation from WakefulBroadcastReceiver class, then you're missing something because WakefulBroadcastReceiver class it's prepared for this situations. If I force to close my app this one can receive notifications from the GCM in my case... Then I have a few questions...
It's obviously that something is incorrect... We need to see your code (Receiver and Intent).
In the other cases you can receive push?
Tell me if I helped you and good programming!

Related

Push notification after onDestroy

I have learnt how to send a push notification, it works well but I need to send a notification to the user even after the app has been closed. So far I know how to send it while the application is running. How do you send a notification when app is in the background or when its even closed, on Android?
There are many answers to this, you could use a Service in background and through that you could do, that service would be running at all times.
If you want your notification to be popped up at some specific point of time, you can specifically use BROADCAST RECEIVER. And with the help of PENDING INTENT, you can easily achieve this task.
About all the above keywords stated, you can easily find in the documentation of Android online.
Hoping that I was helpful...
In case of any more queries... Do ask and clarify.
Thank you...

How can I send notifications if my app is closed?

How can I send my user notifications during the day if my app is closed? It should also work if he hasn't opened the app after a reboot of his phone. How can I implement something like that in my app and what things should I learn for that?
Thanks!
Push Notifications come through GCM (google cloud messaging) on Android. In order to see a tutorial on this you can go to https://www.simplifiedcoding.net/android-push-notification-using-gcm-tutorial/
As per "it should also work if he hasn't opened the app after a reboot of his phone" part, once you register your app with the client, you can employ logic of what happens (or doesn't happen) when you logout of the app. For example, you can unregister from the service so you don't get any notifications.
In your case, if you'd like to keep receiving notifications then you can do so by making sure you keep your token alive, preferably in System Preferences, and handle the case of what happens if the token needs to be updated. (see onTokenRefresh() callback)
First do the happy path and see you can register and receive, and then go and do any additional logic for your notifications.
You can use the AlarmManager for this. It will wake your Application with an scheduled Intent where you can perform your code, e.g. show the notification.
seems to be a duplicate to How to schedule a task using Alarm Manager

Google Cloud Messaging - Will it work when app is not running

I have looked on similar threads however couldn't find a definitive answer.
For android 3.1+, if an app is force killed it doesn't receive broadcasts.
Force killed stops all running services and proccesses.
Does this mean if my app doesn't have a running service and is swiped out of recent apps then it will not receive GCM notifications?
Or does this only apply to when the force stop button is actually pressed.
Maybe you know the (deprecated) version of GCM. There we had to implement a WakefulBroadcastReceiver service which was started automatically when reveicing any GCM notification. This service had to "wake up" your app and in turn is able to start any of your own services.
This of course is still valid for the most recent GCM API-version but there you have to extend GcmListenerService which also is called by a WakefulBroadcastReceiver.
For detailed information on how to implement this please refer to Google's code sample.
To say it short - yes it will work if it is implemented correctly.

Push notification for apps that are not running?

I'm studying GCM now and as far as I see it works for running apps, passing a payload to them and letting the app to deal with it by itself.
However, I've seen apps that are received notifications (or maybe it was Android receiving and showing notification related to the app) when not running. For example, device was turned off. I'm just turning the device on, then turning on Wi-Fi and after a second I see new notifications with the app's icon on it and some text related to in-app events.
How could I implement that kind of notifications?
declare the Broadcast Receiver and the GCMIntentService in the mainfest will allow the Application to get any Message (GCM Included of crouse) if the application not running
BroadcastReceiver
Example and Documantion
For being able to receive GCM's push notifications while the app isn't running you should set up an android IntentService, make it run in the background and set the BroadcastReceiver to listen for GCM notifications.
For more information refer to Google's documentation: GCM information
Check UrbanAirship. I'm using it no my android app.

Receiving GCM Android Notifications while App is not Running

I'm confused by the GCM documentation in how to receive a notification on a client device when the app I'm developing is not running. I've tried googling and reading stackoverflow on this topic, but I haven't gotten complete clarification yet.
Do I just extend GCMBaseIntentService to receive notifications, add the service name to my manifest file, and then my service that extended GCMBaseIntentService will automatically handle notifications to my app, even when the app itself is not running? Is there anything else I need to do?
Thanks!
P.S. I found a thread with a similar title, but it doesn't seem to be the same question.
From doc :-
An Android application on an Android device doesn't need to be running
to receive messages. The system will wake up the Android application
via Intent broadcast when the message arrives, as long as the
application is set up with the proper broadcast receiver and
permissions.
Then what is confusion here?

Categories

Resources