String title = intent.getExtras().getString("title");
String message = intent.getExtras().getString("info");
String lat = intent.getExtras().getString("lat");
String lng = intent.getExtras().getString("lng");
Intent notificationIntent = null;
if(title.equals("blockage"))
{
notificationIntent = new Intent(context, ViewBlockage.class);
}
else if(title.equals("icrequest"))
{
notificationIntent = new Intent(context, IntercarAlert.class);
message=intent.getExtras().getString("reqMessage"); // change the message here for request message
notificationIntent.putExtra("reqName", intent.getExtras().getString("userName"));
}
else if(title.equals("icresponse"))
{
notificationIntent = new Intent(context, InterCarResponseAlert.class);
}
notificationIntent.putExtra("title", title);
notificationIntent.putExtra("message", message);
notificationIntent.putExtra("lat", lat);
notificationIntent.putExtra("lng", lng);
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String appName = context.getString(R.string.app_name);
// set intent so it does not start a new activity
//notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent =PendingIntent.getActivity(context, gcmCounter, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
// update current must for every time get updated pending intent otherwise it will provide wrong intent values
notification.setLatestEventInfo(context, appName, message, pIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(gcmCounter, notification);
gcmCounter++;
答案 0 :(得分:0)
notificationManager.notify(gcmCounter, notification);
每次更改gcmCounter的值。您可以在通知区域中一次看到多个通知。
如果您的应用程序已发布具有相同ID的通知但尚未取消,则该通知将被更新的信息替换。
答案 1 :(得分:0)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
FLAG_ACTIVITY_CLEAR_TASK清除您在点击通知时分配的先前意图和新任务是否已打开第一个通知。