Android多个通知仅显示最后一个

Pac*_*ker 3 java notifications android

我正在创建一个通过FOR循环推送多个通知的通知系统.Logcat显示我正在创建多个通知(手机甚至发送两个与每个铃声相对应的铃声).但通知栏仅显示最后一个.我阅读了文档,并说它调用NotificationManager.notify采用唯一的Id,如果此Id存在,则通知将替换为新的.我为每个通知使用了一个唯一的GUID,但仍然没有成功.

notificationManager.notify(notification.getInt("id"), n);
Run Code Online (Sandbox Code Playgroud)

我可以使用任何建议吗?它可能是通知的PendingIntent部分吗?

提前致谢.

and*_*tud 5

只是确保你使用唯一的id,因为你可以使用for循环整数i值代替notification.getInt("id").

例如:

for(int i = 1; i < 10; i++)
{
  notificationManager.notify(i, n);
}
Run Code Online (Sandbox Code Playgroud)

或者您可以在SharedPrefrence中保存一个整数值,并在for循环中定期递增,并使用与id相同的值.