Skip to content Skip to sidebar Skip to footer

Using Gcm, Urban Airship To Send Push Notification

I have created a sample project in Google Console. Referring the sample from this site, http://code.google.com/p/blog-samples/downloads/detail?name=gcm_sample_update1.rar&can=2

Solution 1:

It is explained here: http://developer.android.com/guide/google/gcm/gs.html Writing the Android Application You have to download and add gcm libraries. Then make changes in manifest:

<uses-sdkandroid:minSdkVersion="8"android:targetSdkVersion="xx"/>

and

<permissionandroid:name="my_app_package.permission.C2D_MESSAGE"android:protectionLevel="signature" /><uses-permissionandroid:name="my_app_package.permission.C2D_MESSAGE" />

inserting Your package name in "my_app_package". Add other permissions

<!-- App receives GCM messages. --><uses-permissionandroid:name="com.google.android.c2dm.permission.RECEIVE" /><!-- GCM connects to Google Services. --><uses-permissionandroid:name="android.permission.INTERNET" /><!-- GCM requires a Google account. --><uses-permissionandroid:name="android.permission.GET_ACCOUNTS" /><!-- Keeps the processor from sleeping when a message is received. --><uses-permissionandroid:name="android.permission.WAKE_LOCK" />

receiver

<receiverandroid:name="com.google.android.gcm.GCMBroadcastReceiver"android:permission="com.google.android.c2dm.permission.SEND" ><intent-filter><actionandroid:name="com.google.android.c2dm.intent.RECEIVE" /><actionandroid:name="com.google.android.c2dm.intent.REGISTRATION" /><categoryandroid:name="my_app_package" /></intent-filter></receiver>

Again write Your package name in "my_app_package". Then declare your service

<serviceandroid:name=".GCMIntentService" />

You have to create a class named GCMIntentService. This class is going to handle the push notifications. It should look like this:

classGCMIntentServiceextendscom.google.android.gcm.GCMBaseIntentService{
     publicvoidonRegistered(Context context, String regId){}
     publicvoidonUnregistered(Context context, String regId){}
     publicvoidonError(Context context, String errorId){}
     publicvoidonMessage(Context context, Intent intent){}
}

In onMessage() you will have to handle the push message. You can use notifications.

Then in Your starting Activity you will have to put this

GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
  GCMRegistrar.register(this, SENDER_ID);
} else {
  Log.v(TAG, "Already registered");
}

in onCreate(). SENDER_ID is the String containing all numbers that you got from the google console.

Solution 2:

Well.. There are 3 steps to get APID 1. Run the application 2. Open logcat 3. Find the APID

Note first time you may get APID(Android Push ID) null so run it again you will get

Solution 3:

If you want to use Urbanairship you have to use their SDK for user registration (look here), cause UA create a new id for each device and not using Google registration Id when pushing message using their API.

Not sure why they doing it like that but that it... =\

Post a Comment for "Using Gcm, Urban Airship To Send Push Notification"