0

This is an effort to develop a Android application which enable C2DM

Things I have done correctly

  • Get a valid Gmail address with C2DM
  • Write an Android app for getting a registrationId from C2DM
  • Get that registrationId from C2DM
  • Pass that registrationId to the third party server (I sent to a php page) (1)
  • Send it correctly (I checked it with the HttpEntity class in the same android app and I got the content of that page)
  • Getting Google authentication ID in server side (used PHP)
  • Open a Gmail account in my emulator (Menu - Settings - Accounts & sync - Add acount)

Things I am confused

  • How that web page (1) get notified when my Android app passed a "http" request?

  • How can I display the registrationId in the web page which sent by my Android app?

Things that wont work

  • Sending PushNotification to the emulator which runs my Android app. Referred this. That code is really good and first part also woks for me. But when I run the sendMessageToPhone() function it sends me 401. In my code I hard coded the values for;

  • $authCode = Google authentication code I get

  • $deviceRegistrationId = Code sent by the C2DM to my Android app

So please help me to clear my confusions and to correct my "wont work" activities.

Community
  • 1
  • 1
AnujAroshA
  • 4,623
  • 8
  • 56
  • 99

1 Answers1

0

Here is a simplest code for sending POST request to PHP:

String url = "http://your.domain.com/path/to/your/post/request/handler.php";
HttpClient client = new DefaultHttpClient();

try {
  List<NameValuePair> post = new ArrayList<NameValuePair>();
  post.add(new BasicNameValuePair("registrationId", "[YOUR ID VALUE HERE]"));

  client.setEntity(new UrlEncodedFormEntity(post));
  client.execute(new HttpPost(url));
} catch(IOException e) {
  //do something here
}

On server side(i.e. in your PHP script) you can use $_POST superglobal variable which is populated from POST data and it's a simple associative array. Something like this:

if (!empty($_POST['registrationId'])) {
  //do something here
}
ioseb
  • 16,625
  • 3
  • 33
  • 29
  • hi... @ioseb thanks for the reply. Can you please send me the "handler.php" code? I have done the Java coding for the Android. But need the PHP script for handle the request sent by the C2DM after I run my Android app. Just the handler.php I wrote PHP script for get Google Authentication ID and send push notification to mobile. Thanks in advance. – AnujAroshA Dec 08 '11 at 11:16