sending message C2DM to google server get error - android

I try to test c2dm app. I have sign up for Android Cloud to Device Messaging. http://code.google.com/android/c2dm/signup.html
I register from my app and sender id to c2dm service and i get registration_id.
After that my third party server must get ClientLogin authentication using email and password. But when i use the registration_id and authorization_id to send message to C2DM Server, i got response AccountDisabled. What does it means? Can you show me how to fix it? Thanks a lot.

I think it's problems with ClientLogin (in the end of page):
http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html

Related

Steps to receive GCM push notification message from app server

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."

Is "Upstream Google Cloud Messaging and User Notifications Sign-up" compulsory?

Is signup for "Upstream Google Cloud Messaging and User Notifications Sign-up" at link "https://services.google.com/fb/forms/gcm/" compulsory to get notification from server app to device?
I have created sample app and sending the sample notification from server. i m getting "OK" response along with message_id, i assume that means my message has been accepted by GCm bit the message is not getting delivered to registered Device? I read somewhere with GCM, registration to the link above is required. I tried that too but i didnt get any response back from google. am i missing anything?
Harshil.
Yes, it is compulsory. When sending a message through GCM, you need to specify a SENDER_ID which is given to you when you create a Project inside, and for this, you have to sign up. So even if you got an OK response, I doubt you specified a correct SENDER_ID so this message probably got discarded.
Maybe this might help:
How to send location of the device on server when needed
As of June 2014, sign-up is no longer required for GCM upstream user notifications (among other features).
There's a post on the Android Developer Blog with more info. Specifically:
At Google I/O we announced the general availability of several GCM
capabilities, including the GCM Cloud Connection Server, User
Notifications, and a new API called Delivery Receipt. This post
highlights the new features and how you can use them in your apps. You
can watch these and other GCM announcements at our I/O
presentation.

Android GCM says Error=NotRegistered, but I registered my app

I am new to Android GCM environment.
I am writing java codes to receive GCM message with Google's 'getting started' page. http://developer.android.com/google/gcm/gs.html
I wrote android client code with them and wrote C# code to send message to GCM server.
My app successfully registered its device and got registration id like 'APA91bGOqUv--of9MyUevAvFq-RNh375O7S5m5y_WvuSwn1zJqbIsGJpzkJda99RIL1jgZ0zC89RC5q8scj3eZMqMeLdTlUsqfSBD_A4jr_000000000000000000000000n_QWhC0Q8KEzQl_icWaBRS4DeMIK_puCzFBO6rArcq8Lax4_YilU'.
But when my C# code call the GCM server - https://android.googleapis.com/gcm/send - to send message, it returns 'Error=NotRegistered'.
I didn't upload my app to official app store, but I don't think it does matter.
Would anyone give me advice to solve this issue?
Thanks in advance.
I found the reason.
Every time when I try to debug, app need to get registered again.
The registration id above is expired.
I received it again, and it worked well.

Connecting to GCM server running at local server

I am working on push notifications with Google Cloud Messaging(GCM). I am able to setup server and client side following this tutorial.
The server runs on Apache Tomcat6.0 (localhost) and Android emulator on Google APIs (API level 17). I have a sender id and API key. When run from the emulator, I get a successful device connection message. Sooner after that, upon sending message from server shows the following error.
com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401()
com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:211)
com.google.android.gcm.server.Sender.send(Sender.java:125)
com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServlet.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
From other posts, I understand wrong API key is the culprit. But in my case, I made sure I am using the right one from the API console.
By the way, when I run the emulator, I saw a message 'sending regId to server'. What is the registration id? It is not same as sender id; looks like an encoded one.
Any break through?
EDIT
The issue is finally solved! Ant was not properly building the WAR file. So API key hardly gets updated. It was hell of a nightmare to spot the bug. Thanks all for the inputs!
I suggest you to read the GCM guide:
GCM guide for Android
The sender ID is a constant that is going to be used in the comunication between GCM and your server. The regsitratiomID (regID) is managed by the GCM service when your phone registers to his service.
A better definition:
http://developer.android.com/google/gcm/gcm.html
Sender ID:
A project number you acquire from the API console, as described in Getting Started. The sender ID is used in the registration process to identify an Android application that is permitted to send messages to the device.
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.
The sender account that you're trying to use to send a message couldn't be authenticated. Possible causes are:
Authorization header missing or with invalid syntax.
Invalid project number sent as key.
Key valid but with GCM service disabled.
Request originated from a server not whitelisted in the Server Key
IPs.
Check that the token you're sending inside the Authorization header is the correct API key associated with your project. You can check the validity of your API key by running the following command:
api_key=YOUR_API_KEY
curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"ABC\"]}"
If you want to confirm the validity of a registration ID, you can do so by replacing "ABC" with the registration ID.
Happens when the HTTP status code is 401.
The Sender ID is the project number what you have created under Google console.
Registration ID
When your application registers to the GCM it gets the registration ID. To deliver the message this registration ID will be used by the GCM to identify your device + your application.
Your android app should send this registration ID to your server so that when server want to send you a message it can tag it with the registration ID, and hence the GCM can deliver it to the right device & right app.
Diagnose whether the registration ID is successfully shared with the server (Get/Post), unless you won't receive any message.

How to send one common C2DM message to more than one device

I want to send one common message say "Happy new year" through C2DM to more than one registered device. I have got few ideas about C2DM from the link http://code.google.com/android/c2dm/index.html and understood that each devices registered for C2DM they have different auth token and registration id. So is it possible for the third application server to send the same message to all the devices registered with. I am using the sample code for Chrome to phone downloaded from http://code.google.com/p/chrometophone/source/checkout.
So any help from any one would be appreciated.
To be clear, the devices don't have authentication tokens. Your application server uses the ClientLogin auth token to authenticate with C2DM for sending pushes. During registration, each device receives a registration ID which it communicates to the application server.
At the moment, C2DM does not support batch sending. You will have to iterate through your devices and send each one of them the same message.
See
this thread for details.

Categories

Resources