gpt4 book ai didi

android - 如何在android中显示多个通知

转载 作者:IT老高 更新时间:2023-10-28 13:06:45 26 4
gpt4 key购买 nike

我只收到一个通知,如果有另一个通知,它会替换前一个通知,这是我的代码

private static void generateNotification(Context context, String message,
String key) {
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 title = context.getString(R.string.app_name);

Intent notificationIntent = new Intent(context,
FragmentOpenActivity.class);
notificationIntent.putExtra(key, key);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.defaults |= Notification.DEFAULT_SOUND;

// notification.sound = Uri.parse("android.resource://" +
// context.getPackageName() + "your_sound_file_name.mp3");
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);

}

最佳答案

只需用这个替换你的行

 notificationManager.notify(Unique_Integer_Number, notification);

希望对你有所帮助。

关于android - 如何在android中显示多个通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18102052/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com