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.
Related
I'm trying to build a GCM notification listener, which will basically use the notification to flag the user that some operation should be made (which involve communicating with my remote App-Server).
I assumed that I should create a UI-less application running on the device's startup and listen to the GCM notifications and issue the internal android notification. When the user opens the notification an activity will be opened which will do the rest of the job with the remote App-Server.
Looking at notification examples it seems to me that I may be missing some basic understanding since all te examples which I had found use a UI application to manipulate the notifications.
What do I miss?
The common use case for handling of GCM messages in Android apps is as follows :
Your app registers to GCM upon startup and sends the registration ID to your server.
Your server sends a GCM message to your app.
You app receives the message in a broadcast receiver, which usually starts an intent service.
The intent service usually displays a notification to the user.
The user taps the notification, which starts an activity of the app.
You can see this use case implemented in the official GCM demo and in many other examples.
The fact that the app you wish to develop has no UI doesn't prevent you from implementing the exact same use case.
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
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?
I have a requirement that my app, can receive events (e.g. messages) from server any time (even if app is not running). So do I need to create an infinitely running service to listen for these events?
This to me seems similar to Email apps in Smartphones, like whenever you receive a new email(event in my case), its able to show notifications and also able to update my list adapter whenever I receive an event.
But I dun know how will I implement this?
You should take a look at C2DM (push-messages):
http://code.google.com/intl/sv-SE/android/c2dm/index.html#intro
it allows a server to send messages to devices at any time.
From the link:
Here are the primary characteristics of Android Cloud to Device
Messaging (C2DM):
It allows third-party application servers to send lightweight messages to their Android applications. The messaging service is not
designed for sending a lot of user content via the messages. Rather,
it should be used to tell the application that there is new data on
the server, so that the application can fetch it.
[...]
An application on an Android device doesn’t need to be running to
receive messages. The system will wake up the application via Intent
broadcast when the the message arrives, as long as the application is
set up with the proper broadcast receiver and permissions.
[...]
Events from server are called "push notifications" and are implemented via "Cloud 2 device messaging" (C2DM). On the mobile side these messages are submitted as broadcast events (see BroadcastReceiver). For a complete example see some tutorials: Google, Vogella or here on Stackoverflow
I think you have to start a Service as soon as the device booted. There is a good tutorial here how to achieve this.
Is there any way to check/manage the push notifications (C2DM or from other service) is available for the Android phone or its based on application to application and have to manage in application only.
Regards,
Android_IT
If your push messages are wap push messages and they are not from your facebook/gmail account, it definitely comes from your other installed application. To detect from which application it comes from just install free app called Airpush detector and detect which apps send push messages and uninstall them.
Here is link for Airpush dector
Yes you can disable it..
Let me explain how? When you want push notification from server then you have to register your device. So same as there is option ofunregisteredif you do not want push notification anymore.So simply check if your device is already registered then unregistered your device.
But next and most important thing which i think you want. In android device there is not option explicitly to stop push notifications.So you have to implement by using code.
On this topic many people have discuss so i am giving you reference.Go through it May this help you
Click me for more help
i too have been receiving annoying push messages on my samsung galaxy s7562. what i did to stop it... i just go to the messaging-settings-push message settings and i simply unchecked the "receive push message from network"...hope this will help.