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?
Related
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.
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!
Google says: "GCM delivers messages as a broadcast. The receivers must be registered in the manifest in order to wake up the application." but What component of Android does actually get the message first? Because İ dont think the Client app is the first component that gets the message by Broadcast receiver.
Would be happy if someone can explain it A bit more or give me A link to a source. Thx
The client app is really the first component to get this broadcast by a broadcast receiver. Not only that, it is the only component to get it, simply because nobody else can listen for that specific broadcast (the one that is defined in your application's manifest).
But I guess you wanted to know who gets the message from the network and sends this broadcast. That is Google Play Services.
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.
I am trying to follow a tutorial on using GCM to push notifications for my application. I have the server up and running, and the android app running. From the server, I can push a notification message, but the notification only pops up when the activity is actually running. How can I register, in my manifest I assume, to answer notifications when the app isn't up and running.
I figured it out, I was missing an adjustment to my manifest and broadcast receiver.