我有一个报警接收器从广播中发出通知。完美运行。现在我添加了另一个通知,并且我喜欢单独提供2个通知。开始第一次通知,稍后开始第二次通知,第二次通知取消第一次通知,所以我只看到第二次通知。我需要在通知栏上有2个通知。另外删除“标志取消”不运行。两个独立的通知
我的代码(第二通知):
String ns2 = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager2 = (NotificationManager) context.getSystemService(ns2);
int icon = R.drawable.ic_launcherlight;
CharSequence tickerText = not1[x];
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "Casual";
CharSequence contentText = not1[x];
Intent notificationIntent = new Intent("com.example.myapp", null, context, NotifyCasual.class);
notificationIntent.putExtra("notify", not1[x]);
PendingIntent contentIntent = PendingIntent.getActivity(context, 2, notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String Sound = prefs.getString("sound", "");
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
final int HELLO2 = 1;
mNotificationManager2.notify(HELLO2, notification);
你到每一个通知给不同的通知ID? – Rahil2952
咦?姆姆姆......不......如何设置ID?谢谢 –
我刚刚给你答案看到它,并接受它作为答案。 – Rahil2952