В вашем классе C2DMReceiver, который расширен от C2DMBaseReceiver.Поместите следующий код в функцию переопределения onMessage, а также напишите функцию с именем createNotification (), которая приведена ниже.
@Override
protected void onMessage(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String msg = extras.getString("data.c2dmsg");
String msgTitle = extras.getString("data.c2dmsgtitle");
String msgTicker = extras.getString("data.c2dmsgticker");
createNotification(msgTitle, msg, msgTicker);
}
}
public void createNotification(String title, String messageText, String tickerttext) {
int icon = R.drawable.ic_stat_notify_msg; // icon from resources
CharSequence tickerText = tickerttext; // ticker-text
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application Context
CharSequence contentTitle = title; // expanded message title
CharSequence contentText = messageText; // expanded message text
Intent notificationIntent = new Intent(this, HomekhawarActivity.class);
Bundle xtra = new Bundle();
xtra.putString("title", title);
xtra.putString("message", messageText);
notificationIntent.putExtras(xtra);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, PendingIntent.FLAG_ONE_SHOT
+ PendingIntent.FLAG_UPDATE_CURRENT);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.FLAG_AUTO_CANCEL;
notification.flags = Notification.DEFAULT_LIGHTS
| Notification.FLAG_AUTO_CANCEL;
final int HELLO_ID = rand.nextInt();
mNotificationManager.notify(HELLO_ID, notification);
}