In GCM Docs, his data:
It does not provide a built-in user interface or other processing for message data. GCM simply sends the raw messages received directly to the Android application, which completely controls how to process it. For example, an application may publish a notification, display a user interface, or silently synchronize data
But nothing about how to create a notification user interface.
How to create a user interface, for example, a small dialog with two buttons, etc., for notifying GCM. Like gmail, you can archive or delete mail from the status bar message.
CODE:
public void onReceive(Context context, Intent intent) { GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); ctx = context; String messageType = gcm.getMessageType(intent); if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED .equals(messageType)) { } else { sendNotification(intent.getExtras().getString("msg")); } setResultCode(Activity.RESULT_OK); } private void sendNotification(String msg) { mNotificationManager = (NotificationManager) ctx .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, new Intent(ctx, NotificationsActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( ctx).setSmallIcon(R.drawable.ic_launcher) .setContentTitle("GCM Notification") .setContentText(msg); mBuilder.setContentIntent(contentIntent); Notification mNotification = mBuilder.getNotification(); SharedPreferences sp = ctx.getSharedPreferences( GCMDemoActivity.GCM_NOTIF_PREF, Context.MODE_PRIVATE); long diff = System.currentTimeMillis() - sp.getLong("last_gcm_timestamp", 0); if (diff > TWO_MINUTES) { mNotification.defaults = Notification.DEFAULT_ALL; SharedPreferences.Editor editor = sp.edit(); editor.putLong("last_gcm_timestamp", System.currentTimeMillis()); editor.commit(); } mNotificationManager.notify(NOTIFICATION_ID, mNotification); }
thanks
source share