How to catch C2DM notice coming to the phone? - android

Is it possible for android enabled phone to intercept all C2DM notifications? If so, which way should dig.

Few days back the announcement came that C2DM will be officially deprecated.
At that time C2DM stopped accepting new users and quota requests.
C2DM has been replaced by Google Cloud Messaging for Android (GCM). The C2DM service will continue to be maintained in the short term, but developers must use GCM for new development.
So in near feature we may need to move existing C2DM applications to GCM to take advantage of GCM features.

No, it's not possible to intercept C2DM or GCM messages. The system won't deliver them to your interceptor. They are not delivered via an unsecured Broadcast Intent.

Related

What should I use for push notification(No Google Cloud Message)

I want a push notification, when there is data in server change,delete or added etc The notification is associated with the user. And the Google Cloud Messaging notification is associated for the application running in device. Also there is a lot of over head for developers, when developer are creating the system using google cloud message. Therefore I decide not to use Google Cloud Message.
I know is using XMPP or WebSocket can fulfill my requirement but it is battery inefficient. My question is there a better approach to fulfill my requirement.
You can send the GCM registration Id in the login request to the server and remove it once the user logs out. This way you can send a GCM message to a particular user.
If you want to use a GCM alternative you can try Pushy.me, its also a very good service that uses MQTT protocol and have less headaches as compared to GCM.
Depending on your specific needs, using an alarm and intent service to poll your server every so often - say 24 hours - can work. Then create a local notification if needed. This way no third parties are needed, but you won't have real time notifications.

How to trigger notifications in Android?

I am building an Android app with a server at back end. What I want to do is, whenever anything new is updated in server the app should trigger a notification into the users phone showing the newly added content.
EDITED TO ADD: This is even more important as of Android M and beyond. As part of a comprehensive effort to improve battery life, the OS actively restricts many of the techniques that apps have used in the past for sync and notifications. Use built-in methods like JobScheduler and GCM in order to avoid issues.
The core notification mechanism in Android is Google Cloud Messaging (GCM), documented here. It's built in to the platform at a low level and directly supported by mobile networks, so it's usually the most efficient choice. It doesn't have a guaranteed latency, so it may not be appropriate for very time-sensitive messages, but it's generally quite fast--at least as fast as sending SMS, for instance.
There are a number of different commercial products as well as FOSS libraries that wrap GCM in various ways, for instance to provide support for very old (pre-Froyo) devices or devices without Google enabled, or to provide a single cross-platform solution between various competing mobile platforms. Firebase, Parse, and Urban Airship are some that I'm aware of.
To use GCM, you need to get an API key from Google. You use this API key to authenticate requests to the GCM server. Once you have a key, sending a notification is as easy as sending a POST request to the GCM server. GCM also supports XMPP, but I haven't used it.
On the client side, your app needs to call the GCM API to register for messages. You provide the project name that you used to create the API key, so that GCM knows which server messages should go to your client app. Once your app has registered, incoming messages will be sent to it as intents, which you can receive by implementing a BroadcastReceiver.
There's a tutorial on the Android developer site that walks you through the GCM process.

Can an android work on both GCM and C2DM?

I have an app that currently uses C2DM for push notifications. I would like to inquire if I update the app to GCM and if some users do not upgrade their app, will Google allow me to use both the C2DM and GCM for the two versions of my app?
Or will the users on my previous app never receive a PUSH notification altough I still have the push logic implemented for C2DM?
I've completely replaced C2DM with GCM in the app, and left support for both protocols in the server side. Works like a charm; details are here.
They will still receive them as long as you don't remove any authorisation keys, ids etc. as GCM uses the Project ID while C2DM uses the registered e-mail address.
More on it here: C2DM to GCM Migration
Once the C2DM service was deprecated recently I advice you to migrate your pushes system to GCM service.
The best way to deal with it is doing the thing like Google says. Take a look at this topic in the official GCM's documentation.
While not the original question, an interesting one would be: Can one app simultaneously use C2DM and GCM.
C2DM uses the Sender-Account while GCM uses the Project-ID to register. The only thing they both might share is the App-package name (and obviously the google account of the device, but that shouldn't matter as there are multiple apps which can use gcm/c2dm in parallel anyway).
In my experience registering C2DM and GCM in the same app can cause some serious problems.
Reason to have both in one app might be that you want to use GCM in the app, but can't everywhere because a legacy backend might not be able to switch to GCM yet. Probably a rather rare scenario - but currently happening for our app.

Google Push Notification

Just now Google introduced Google Cloud Messaging for Android. But here problem is that end user must have atleast one google account to use this service. is possible to skip GCM and send push notification end user or suggest any other way?
Important: C2DM has been officially deprecated as of June 26, 2012. At that time C2DM stopped accepting new users and quota requests. C2DM has been replaced by Google Cloud Messaging for Android (GCM). The C2DM service will continue to be maintained in the short term, but developers must use GCM for new development. We also encourage developers to move existing C2DM applications to GCM to take advantage of GCM features. See the C2DM-to-GCM Migration document for more information.
Well this is part of C2DM prerequisite Can't skip this mate.. thanks
To use GCM user have to be registered in goggle service. If you distribute you application only by Google Play this is not a problem.
There are alternatives but they have lots of disadvantages: sending SMS (you have to pay for it); implement own Push Notifications (by polling your server) - it is easy to make some mistake and drain phones battery and requires lots of work.

how to set valid time period for android c2dm message?

I would like to implement a feature that only delivers messages to devices at specific periods. After the valid time, messages would be abandoned. Can anyone suggest me how to do this?
C2DM itself doesn't have such a facility so you have two choices:
Your server app only sends messages during certain times
or
Your Android app receives the C2DM messages all the time, but during certain times you ignore/handle as appropriate.
Google just released a new version of c2dm called "Google Cloud Messaging (GCM)" at I/O 2012. With GCM its possible to define a timeout for your messages.
GCM ttl section: http://developer.android.com/guide/google/gcm/adv.html#ttl
You can find my answer to a similiar question here:
https://stackoverflow.com/a/9709944/789738

Categories

Resources