Search code examples
androidandroid-c2dm

Push Notifications in Android


I'm turning to you as my last resort. I believe, I've read every single tutorial on how to do push notifications in android out there, but every tutorial was missing something or it didn't work entirely.

So what I would like to do is just to display a simple notification in the status bar, to let the user know, that there is new information available in the app.

I think the right way to go here is C2DM. My problem is, I have no idea whatsoever how to implement it on the app or on the server side.

I don't need anything fancy, just maybe a php-script that sends out a sentence or something. And a code snippet to put in my app so that it registers with the server. I am having my own server which does server my iOS push, so no probs here.

I would really really appreciate it, if you could provide me with a step-by-step tutorial on how to get this working.

Thanks for the Tip, I'm getting errors on this code though:

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");

        registrationIntent.putExtra("app", PendingIntent.getBroadcast(context, 0, new Intent(), 0));

        registrationIntent.putExtra("sender", "[email protected]");

        context.startService(registrationIntent);

It says context cannot be resolved to a variable, but the tut didn't tell me to create it or told me the type of the variable.


Solution

  • I think this tutorial will help you.

    http://blog.mediarain.com/2011/03/simple-google-android-c2dm-tutorial-push-notifications-for-android/

    https://developers.google.com/android/c2dm/#push

    http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html#c2dm_sendmessage

    This tutorial is about sending push notifications using GCM and PHP

    http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/