我将不同的通知发布到通知栏。
所有人都有不同的身份证明,但意图是针对同一活动。
当我点击第一个通知时,活动开始并点击完成。
当我的活动完成后,栏中的所有剩余通知都将消失。
我希望他们留在通知栏上。
如何实现这一点。
这是代码。
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int id = 10;
notificationIntent = new Intent(context, MyAct.class); // creating intent.
notificationIntent.putExtra("data", data);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// defining actions while notification.
contentIntent = PendingIntent.getActivity(context, id,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification = new Notification(R.drawable.icon, message,
System.currentTimeMillis());
notification.setLatestEventInfo(context, "Hello", message,
contentIntent);
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
mNotificationManager.notify(id, notification);
id++;
提前致谢....!
答案 0 :(得分:3)
您需要在清单文件中为该活动添加以下属性。
android:launchMode="singleTask"
android:taskAffinity=""
android:excludeFromRecents="true"
答案 1 :(得分:0)
听起来您错误地创建了通知。我建议你重新阅读Notification.Builder类的javadoc,看看你做错了什么。您可能忽略了调用setAutoCancel(),或者重新使用相同的对象发布通知。
答案 2 :(得分:0)
您可以尝试使用正在进行的标记http://developer.android.com/reference/android/app/Notification.html#FLAG_ONGOING_EVENT,或者在活动的新内容方法的状态栏中添加通知