android 每个应用的系统通知限制
android system notification limit per app
这可能与主题无关,但我找不到任何相关内容。
应用程序可以显示的通知数量是否有限制android?我在收到 100 个通知后遇到问题。没有文件明确说明这一点。
注意:显示 100 条通知并不是一个好主意,但出于某些原因,这是必需的。
运行 这个:
// 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);
}
当应用程序崩溃时,您会看到有多少通知..
根据@Nirel 的回答。
1) 我尝试 运行 3 种不同设备中的代码。
令人惊讶的是超过 50 的通知没有显示在通知区域。
它给出以下错误。
W/NotificationManager﹕ notify: id corrupted: sent 51, got back 0
后续调用出现同样的错误。
我看到了 NotificationManager 的来源,如果传入和传出 id 不同,它会给出这个错误。请参阅下面的代码。
2) 在我尝试以 100 毫秒的间隔通知之后。
同样报错。我尝试的是在执行代码时删除 1 个通知。
奇怪的是,状态栏中出现了第153号通知
所以结论是,最多可以有50条通知。这可能是默认行为,如@Sharp Edge 所述,制造商可能会更改。
谢谢。
在 API23 中
包com.android.server.notification;
NotificationManagerService.java
静态最终整数 MAX_PACKAGE_NOTIFICATIONS = 50;
通知和 toasts 的限制是每个应用 50
这个 post 确实帮助我研究了这个主题。我已经写了一篇关于这个的文章,比如你如何修改你的逻辑并保持 posting 通知,即使你已经通过妥协最旧的通知达到最大限制。 https://medium.com/mindorks/the-notification-limit-per-app-in-android-94af69a6862c
在 Android 10 个通知抽屉中,每个应用的通知限制从 50 条下降到 24 条
。
了解更多信息 here。
这可能与主题无关,但我找不到任何相关内容。
应用程序可以显示的通知数量是否有限制android?我在收到 100 个通知后遇到问题。没有文件明确说明这一点。
注意:显示 100 条通知并不是一个好主意,但出于某些原因,这是必需的。
运行 这个:
// 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);
}
当应用程序崩溃时,您会看到有多少通知..
根据@Nirel 的回答。
1) 我尝试 运行 3 种不同设备中的代码。
令人惊讶的是超过 50 的通知没有显示在通知区域。
它给出以下错误。
W/NotificationManager﹕ notify: id corrupted: sent 51, got back 0
后续调用出现同样的错误。
我看到了 NotificationManager 的来源,如果传入和传出 id 不同,它会给出这个错误。请参阅下面的代码。
2) 在我尝试以 100 毫秒的间隔通知之后。
同样报错。我尝试的是在执行代码时删除 1 个通知。
奇怪的是,状态栏中出现了第153号通知
所以结论是,最多可以有50条通知。这可能是默认行为,如@Sharp Edge 所述,制造商可能会更改。
谢谢。
在 API23 中
包com.android.server.notification; NotificationManagerService.java
静态最终整数 MAX_PACKAGE_NOTIFICATIONS = 50;
通知和 toasts 的限制是每个应用 50
这个 post 确实帮助我研究了这个主题。我已经写了一篇关于这个的文章,比如你如何修改你的逻辑并保持 posting 通知,即使你已经通过妥协最旧的通知达到最大限制。 https://medium.com/mindorks/the-notification-limit-per-app-in-android-94af69a6862c
在 Android 10 个通知抽屉中,每个应用的通知限制从 50 条下降到 24 条
。
了解更多信息 here。