This works fine under the following three conditions:
1. If the application is already open and click on the notification, the notification should be removed from the status bar.
2.if the application is open and in the background, then the application should resume from any previously open screen.
3. The application closes and clicks on the notification in the status bar, after which the application should open.
private final static int NORMAL = 0x00; private final static int BIG_TEXT_STYLE = 0x01; private static NotificationManager mNotificationManager;
in onMessage call
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); new CreateNotification(BIG_TEXT_STYLE, team, message).execute();
then declare the next class in the GCMIntentService. Public class CreateNotification extends AsyncTask {
int style = NORMAL; String team, message; public CreateNotification(int style, String team, String message) { this.style = style; this.team = team; this.message = message; } @Override protected Void doInBackground(Void... params) { Notification noti = new Notification(); switch (style) { case BIG_TEXT_STYLE: noti = setBigTextStyleNotification(team, message); break; } noti.sound = (null); noti.defaults = 0; noti.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.beep); noti.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(0, noti); return null; } }
and finally
private Notification setBigTextStyleNotification(String team, String message) {
source share