这可能与主题无关,但我找不到相关内容。
安卓应用程序能够显示的通知数量是否有限制?在显示100个通知后,我遇到了问题。没有明确说明这一点的文档。
注意:显示100个通知并不是一个好主意,但出于某些原因是必需的。
安卓应用程序能够显示的通知数量是否有限制?在显示100个通知后,我遇到了问题。没有明确说明这一点的文档。
注意:显示100个通知并不是一个好主意,但出于某些原因是必需的。
W/NotificationManager﹕ notify: id corrupted: sent 51, got back 0
在API23中
包名为 com.android.server.notification 的 NotificationManagerService.java 文件中,存在以下代码:
static final int MAX_PACKAGE_NOTIFICATIONS = 50;
该变量指定了每个应用程序的通知和Toast消息的限制数量为50。
这篇文章对我在研究这个话题时帮助很大。我写了一篇关于如何修改逻辑并通过牺牲最旧的通知来保持发布通知的文章,即使你已经达到了最大限制。https://medium.com/mindorks/the-notification-limit-per-app-in-android-94af69a6862c
运行以下命令:
// prepare intent which is triggered if the
// notification is selected
Intent intent = new Intent(this, NotificationReceiver.class);
// use System.currentTimeMillis() to have a unique ID for the pending intent
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
// build notification
// the addAction re-use the same intent to keep the example short
Notification n = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
for(int i = 0;i<1000;i++)
{
Log.d("Tag", "notification number" + i "just published")
notificationManager.notify(i, n);
}