We are developing apps both in IOS and Android. GCM push notification has been enabled for IOS and its working fine now. The package name for both the platforms are going to be the same.
I was given SERVER API KEY and SENDER ID by ios developer to set up gcm for android. While looking for the steps, I came across https://developers.google.com/cloud-messaging/android/client.
I kept to myself that the steps listed in the contents need to be done to set up GCM for android (please correct me if I am wrong).
Get Config file and add it to Android project
Set up Google play services (I added gcm in my project dependency)
Add entries to Manifest file
Check for google play services APK
Obtain registration token.
"An Android application needs to register with GCM connection servers before it can receive messages"
"The client app should store a boolean value indicating whether the registration token has been sent to the server." - My backend team told me I dont need to send them anything I have to just configure gcm in the app and the app will receive messages from backend.
So, My question is Do I need to have RegistrationIntentService and MyInstanceIDListenerService. Also, Do I have to define my InstanceIDListenerService in Manifest?
Our backend uses device id to send push notifications to devices so they dont need registration token to be sent to them as we send device id. So in this case, Should I register my app with GCM using RegistrationIntentService and InstanceIDListenerService? if so, should the app keep the registration token with itself. Is this registration needed?
GCM supports three types of downstream (server-to-client) messaging: send to a specific device (also called "simple" or "targeted"), send to a topic, or send to a device group. Your question says, "our backend uses device id to send push notifications to devices". It is not clear what "device ID" is and which type of messaging you intend to use. Your backend team has told you that you "don't need to send them anything". If that is true, I don't know where they are getting the "device ID".
Each of the three types of messaging provided by GCM require client devices to register with GCM and obtain a registration token. To send a message to a specific device, the registration token is effectively the "device ID". So yes, you need to implement something similar to the RegistrationIntentService and InstanceIDListenerService described in the documentation.
The description in the documentation about needing to send the registration token to the App Server is misleading. That is only required for targeted messaging. The documentation for receiving topic messages states: "Note that, for topic messaging it's not required to send the registration token to your app server; however, if you do send it, your server can verify the validity of the token and get more information about the app that created it."
Related
I was wondering how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application for which it was intended ?
Can anyone let me know how it is done ?
You question : how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application.
From your question it looks like you willing to know about data
workflow & Client Server architecture that exists in applications
which are using the GCM service.
As per google’s documentation “Google Cloud Messaging for Android (GCM) is a service that helps developers send data from servers to their Android applications on Android devices”. GCM is a service provided by Google for developer that helps developer to send data from server to any number of Android devices.
Simplified Application Specific Work-flow:
The push notification can be broadcasted either to the mass audience
or a select set of users. Mass audience is targeted when the
notification has to be sent about a marketing campaign. A subset of
users are targeted when a personalized information has to be sent.
The below steps explains how push notification works on android devices:
First android device sends sender id, application id to GCM server
for registration.
Upon successful registration, GCM server issues registration id to android device.
After receiving registration id, device will send registration id to our server.
Our server will store registration id in the database for further use.
Whenever push notification is needed, our server sends a message to GCM server along with device registration id (which is
stored earlier in the database).
GCM server will deliver that message to respected mobile device using device registration id.
This can also be understand using following figure
An Example Workflow:
So, from above images it easy to understand that whenever the android
application is first installed by the user, then it registers itself
to GCM server, and obtains unique GCM ID, then it's our Host servers
responsibility to keep this newly registered Registration ID of the
android user into Database, and then it will be used whenever server
side application willing to send the message to that particular
android user.
So, let us consider one case; suppose an Server wants to send Some data to Android User, which has already registered it's GCM ID 1234567 when it's first time installed, and as it's in the server's database the server application will fetch it from DB, and simply make a HTTP POST request to the GCM server in JSON format, which will have registered user's GCM ID along with the data to send , in same way the GCM Server has the record of all the Registered GCM/Android Clients, it directly forwards that message to the intended android user, and android app in user's phone will raise and Notification alert, to indicate an push notification has arrived.
Hope This answers an question!
GCM stands for Google Cloud Messaging.
Every push notification receive on any Android device is sent by the GCM only.
sender -> GCM -> Android Device
when sender sends an push notification then it goes to GCM. GCM receives that push and forward it to particular Android Device by its Unique device id.
GCM can't deliver Push without Unique Device ID.
while implementing push notification there are two important things, application key and server key ... these are unique Keys.. using these keys GCM identifies the application to whom push notification is related
how to get SNS working in Android?
We have an app that sends SNS messages to iOs apps already (I personally am only working with the App side). And have extended it to send Android messages. It works fine for iOS and thinks it is sending to Android correctly but no message ever actually shows up on the Android device.
I am registering with the backend by getting the Settings.Secure.ANDROID_ID and sending that to the web service that registers it with Amazon SNS.
I have turned on all the permissions that I can (I don't need to specifically ask for permission do I?, how would I do that).
Basically the setup we have is I hand our web service a device id and it registers with Amazon and the web service sends the notifications out (but I am never seeing them).
Is there anything else I need to do or check on the client side?
Amazon SNS for push messaging on android instructions is the same as normal GCM on android.
You must follow the directions here:
GCM Getting Started - covers the google console set up and will provide you with the :
SenderId, for use in the android app code. (This is the Google Console's Project #)
the api key, for use in SNS server setup
Implementing GCM Client - covers client library, getting the registration ID, setting up a wakeful service and broadcast receiver for creating notifications or whatever you'd like you app to do when it receives a push.
You should also read thru amazon's documentation Getting Started with Google Cloud Messaging for Android which summarizes the the previous two links.
I am registering with the backend by getting the Settings.Secure.ANDROID_ID and sending that to the web service that registers it with Amazon SNS.
This is not correct. By using the GCM client library, call the following methods to get the real registration ID (sns likes to call them an endpoint) that you can send to the web service that registers it with Amazon SNS. There should be no need to use Settings.Secure.ANDROID_ID at all for push on android.
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(someContext);
String registrationId = gcm.register(senderId);
I have turned on all the permissions that I can (I don't need to specifically ask for permission do I?, how would I do that).
see Implementing GCM Client for the required permissions that you must include in your AndroidManifest.xml. And no, you don't need to specifically ask for permission since it would be in the AndroidManifest.xml but you could ask the user on first app start with a dialog or some other UI. You may also choose to let the user disable push for you app via a settings screen if your app has one.
Is there anything else I need to do or check on the client side?
You should confirm that you are able to get registration ids (perhaps some logging)?
And then with those ids, test your implementation. Here is a question that was asked a while ago that will help you use a rest client to send pushes with your registration ids and api_key (SNS login not needed).
How to push notification from rest client for testing purpose
Can anyone help me with a way to send requests as a notification through my android app to all the users who have installed my application and then their responses are sent back to the user who sent the request.
I have read about GCM but I dont understand how can I register all the users to get their GCM registration ID and how can i simulataneously send a notification to all users..I may sound naive but I am completely new to this GCM concept and I dont think that it is the exact thing what I am looking for..
So,somebody please tell me how to send notifications(simultaneously on click of a button or something..) to all the users who have registered in my android app .
You will need to build a server component that keeps track of all registered users. This component will be an app that you write and expose in the cloud. There are many app-hosting services to choose from. Amazon EC2 is one example.
So the app flow would be something like this:
User launches your Android app.
Android app registers itself with GMC. GCM will respond with a token that represents that device.
Android app POSTs that device token to your cloud application.
Cloud application saves that token. The app should now have a list of tokens that represents all active devices running your app. (of course you may want to have an expiration policy - i.e. remove all tokens corresponding to devices you have not heard from in say 30 days).
One of your app users posts a message that s/he wants to broadcast.
Your Android app responds by sending a request to your cloud application.
Your cloud application responds to this request, by making a request to GCM. In this request (or series of requests), the app will include all device tokens and the user-entered message.
GCM responds by pushing the message to all devices with your app (i.e. all of those that have register with GCM and received a token - see step 2).
If using GCM alone you would need to write a server component. I get the impression you don't want to do this. You could use Urban Airship push messaging, which will allow you to send out a message to all registered apps from the Urban Airship web portal. Urban Airship integrates with GCM (which is easy to setup). You would still need to add code to your app to handle the push notification the app receives.
http://docs.urbanairship.com/build/android.html
All,
I'm probably asking a very basic question here, but how does one get your device ID for PushSharp in Android? My setup is VB.net, and we'll be sending to a large number of different Android devices.
Following the PushSharp example here is my code so far:
push.RegisterGcmService(new
GcmPushChannelSettings("YOUR Google API's Console API Access API KEY for Server Apps HERE"));
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId(
"DEVICE REGISTRATION ID HERE")
.WithJson("{\"alert\":\"Hello World!\",
\"badge\":7,\"sound\":\"sound.caf\"}"));
I know the API key is from the GCM service, but where does the Device Registration ID come from? Is that setup by the GCM service? Or is that something the android device sends the server should save?
Thanks for the help.
The registration ID is assigned by the GCM service. When the application registers to GCM, it gets a registration ID and should send it to the server.
Registration ID An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID, it sends it to the 3rd-party application server, which uses it to identify each device that has registered to receive messages for a given Android application. In other words, a registration ID is tied to a particular Android application running on a particular device.
You can read more about it here.
In case you ended up reading this post and could not get yourself sorted out with the selected answer, here is the ultimate link that helped me:
Getting a GCM registration ID
The Android C2DM push app that I have developed has the reference of my sender is (example: "sender#gmail.com") in the application side code.
Case 1:
When I install this app on a Android device, the device has a gmail id as "personalid#gmail.com" in Accounts and Sync settings.
App is registered successfully with C2DM but it does not receive any of the pushed messages.
Case2:
When I use the same sender id ("sender#gmail.com") in the Android device's Accounts and Sync. I receive all the messages that I push.
Why case 1 is failing and case 2 (sender id all through) is successful?
Please make sure that you have signed out from built in gtalk application of your phone, if you are not signed out from gtalk app, then it will create ambiguity in between gtalk and ur personal app for messaged pushed from google server so it can not send message to any app and give exception.
For detailed information of push notification , please check https://developers.google.com/android/c2dm/
best c2dm tutorialis ,http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html
This is the way that C2DM works. It makes sense that it works in this way since it requires the email address for both the registration id and authentication token.
When sending a push message, your third party server uses the registration id built on (probably) "sender#gmail.com", and authentication token built on the same email. Google's server looks on your device and tries to find that specific email address account. You can have multiple accounts on the device, but at least one of them has to be the account used to register the device.
Why would Google ask for the email anyway if it wouldn't have mattered? It would have been much easier to use directly the device's unique id.