I have an Android application that uses C2DM. I am creating another application derived from it. Currently, Google don't support C2DM, they moved to GCM.
But I want to use the C2DM for the derived app still. Is it possible to add multiple packages that can be notified via C2DM in the manifest?
You're confused. A single server can notify multiple apps, the C2DM/GCM rules don't prohibit that.
The apps would have different package IDs, but the notification generating code on the server does not need to know them. All the server needs to know is a registration ID. Which the app obtains, and somehow transmits to the server.
The app needs to provide an API Key (GCM) or Google account (C2DM) at registration time to subscribe to notifications. But not vice versa, the server does not need to authenticate against packages.
If the notification protocol varies from one app to another, you need to communicate the supported protocol along with the reg ID to the server.
Related
Is GCM the only way for push notifications in android? And is it advisable over other methods (if there are any)?
So let's say my app from a device registers on GCM. Is it the app itself which is assosciated with the device that registers itself, or the user and his email id that register? If my user switches devices in future, will the same 'registration token' work for him ? Or in a similar scenario if a user with another g-mail id registers to my app from the same device, do i push notifications to the same device with 2 different registration tokens?
Extending to what i asked in 2, suppose a single user has his g-mail id working on my app on different devices. Does GCM push the notification to all those devices, or only one of them? And if one, then how does it prioritize?
No, there are other push notification services in Android, like Parse. However, it is strongly recommended to use the default push notification service that is present in any Android device that has Google Play Store, because that reduces battery usage. If you are pushing your app somewhere else though, like Amazon Store, keep in mind that Kindle Fire does not comply with this and doesn't have Google Play Services -- at least as far as I know.
The registration token is very volatile and is not bound at all to an email. Actually, sometimes the same device may get a new GCM ID out of the blue. There are many tutorials on GCM's best practices, but Google's is the best way to start. What you should do to prevent problems is store the GCM id of your device in your database, so you can always know which ID is currently associated to your device. GCM may give you new IDs for no reason, so always parse its response properly and store the new ID it may provide, linking it to the device.
GCM doesn't really care which Google account is your app using. That means you can register as many devices as you want with the same account. You have to manage to which devices you push notifications, because the ID is managed by device.
Be careful: there's been some changes with the API lately, so a lot of unnoficial tutorials you find on the internet may point to deprecated methods.
There are other ways of sending notifications, Tokodu and RabbitMQ for example. I wont go over if X is better than Y, since it's not allowed on StackOverflow.
A unique device token is generated for the device, how you use this device token is totally up to you. You can make it unique for the user by, for example, implementing a login system, so that the device token is created and stored in a database (together with the user information). Let's say if two different users uses your application on a shared device, they can both receive notifications on the same device if you allow them to. It depends on your own implementation.
This again depends on how you chose to implement the GCM features on your client and server side. For example, you can choose to store device tokens for each and every device the user has installed the app on, or you can store the latest device token so that notifications are only sent to one of the user's devices.
I hope this helps clear some things up.
Besides good answers above, if you need a push notification solution for a working environment without Internet access, I suggest SignalR of Microsoft, which has already supported Android and Java (you can find out more at GitHub).
Hope this helps little!
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.
I am new to android development,I am working on push notification app now and trying to get overview of concepts about GCM and got stuck with one of the concept about use of "endpoint".
I am going through below google developer link:
https://developers.google.com/eclipse/docs/endpoints-addgcm
they have given something like this
Google Cloud Messaging (GCM)allows your Cloud Endpoints to send
notifications to registered Android devices whenever the state of a
resource changes. For example, suppose a user uses a Note application
from 2 devices: Device A and Device B. If the user is adding a note
from Device A. Google Cloud Messaging can be used in the Cloud
Endpoint for the insert operation to ping Device B to indicate that a
note has been added.
my questions are
1>> Is GCM itself an endpoint?or it is a separate entity?
2>> how to interact with 3rd party app server without using endpoint for server and client?
Thanks in Advance!
GCM and Cloud Endpoints are separate and unrelated Google services (though one possible source of confusion is that the term 'endpoint' is often also used in more generic ways).
Endpoints is a service for creating public API's for GAE app's. It can make it easier to create the API's that will allow your clients to communicate with your GAE app, particularly if those clients are iOS, Android, or Web apps (the supported client types), and if you want to use OAuth2 authentication for the apps or their users.
GCM is for waking up, and pushing data to, your apps on those same platforms. It is true that your server app will probably use both GCM and Endpoints, they are separate and unrelated.
I read about Google Cloud Messaging at http://developer.android.com/google/gcm/gcm.html.
It supports Third Party Application server to Android application push notification.
I am wondering whether it is possible to implement the same thing push/receive notification from an Android app on one mobile to the same Android app on another mobile using Google Cloud Messaging.
If not, is there any other free service available similar to Google Cloud Messaging?
An Android device can send a GCM message to another Android device. All it needs is the API Key (of the Google API Project ID that the app uses to register to GCM) an the Registration ID of the other device. Using these parameters it can send a GCM message to another device via an HTTP request.
Usually applications that use GCM require a 3rd party server in order to store the Registration IDs of all registered devices. If your app has a different way to let devices share their Registration IDs with each other without requiring a server, you don't need the server.
As far as I'm aware, there has to be a server in the middle to send the push notifications (Android -> Personal Server -> GCM Server -> Android)
So the Android device sending the notification would send some data to a script on the server (using a HTTP GET/POST), and that script would then send the push notifications to all the devices that you wanted it to
Following the example Code from google (GCM Client Example), you can build an app to get a registration ID for your device, but sending messages without a server wouldn't work in my opinion. I didn't tried by now, but what about using the Google Backend Starter, or (what I tried) using a Backend as a Service Provider like apiOmat if you can't afford or don't want to set up a server.
sorry for my bad English.
i am developing an Android application which include chat functionality. i am planning to upload two versions on Google play. one is lite version and one is pro. i am using GCM to include chat functionality.
i want to ask is it better to upload two versions of app to market instead of one application with in-app purchase. and if i upload two apps then how to differentiate those applications to use different GCM Id's.
i know it not a programming question but i need help on it.
any suggestion.
I'm not sure how to answer the first part of your question (two apps vs. one app).
As for the second part, if you upload two applications, you can either use the same sender ID to register to GCM for the two apps, or use a different sender ID to register each app to GCM. Either way, if you install both apps on the same device, each would get a different Registration ID from GCM.
When sending a GCM message from your server to the apps, you would have to either use the same API key (if you used the same sender ID in the registration to GCM) or different API keys (if you used different sender IDs).