Question

I have created a android gcm client and got the reg id from the gcm server. Now I want to pass this id to my server code where it sends the messages to gcm server. What I have done is manually copied the reg id from logcat and pasted in the server codeq. This approach is working in emulator but not in phone as I won't be knowing the reg id in phone. Can someone please share the code snippet on how to pass the reg id to server side method programmaticaly. Thanks in advance.

Was it helpful?

Solution

The short answer is: use HTTP.

The longer answer is as follows. First, put together a Web page that takes a RegID as one of the parameters. Depending on the nature of your Web server, there might be different technologies for that (PHP, ASP.NET, servlets). The page would take a RegID from parameters and store it in some permanent medium (database? file? you decide). By "parameters" I mean - either query string or the POST form. The latter is better, as those RegIDs can get quite big.

The page would need a public URL of some kind, one that your Android app can reach (i. e. not http://localhost). An IP address URL would work.

Finally, in your Android app, in the part where the RegID is received, use HttpClient to perform a Web request, passing the RegID that you've just got as a POST parameter.

As for ready to use snippets... Too many variables for that. For one thing, half the code is server-side, and we don't know what server-side tech are you using. The Android part - just look for an HTTP POST example for Android. The 'Net is choke full of those.

Also, do accept some answers. That's how we roll here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top