gpt4 book ai didi

Android 不显示所有通知

转载 作者:行者123 更新时间:2023-12-02 12:23:31 24 4
gpt4 key购买 nike

我做了一个可以同时发送很多通知的应用程序,问题是如果通知的数量大于 6 或 7 个,并不是所有的通知都会显示,尽管日志说所有的通知都已创建并且有唯一 ID。

这里是通知服务的代码

class GeofenceService : JobIntentService() {

override fun onHandleWork(intent: Intent) {

if (intent.action == GeofencingConstants.ACTION_GEOFENCE_EVENT) {
val geofencingEvent = GeofencingEvent.fromIntent(intent)

if (geofencingEvent.hasError()) {
val errorMessage = errorMessage(this, geofencingEvent.errorCode)
Log.e(TAG, errorMessage)
return
}

if (geofencingEvent.geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
Log.v(TAG, this.getString(com.superapps.ricardo.smithnotes.R.string.geofence_entered))

val fenceId = when {
geofencingEvent.triggeringGeofences.isNotEmpty() ->
geofencingEvent.triggeringGeofences
else -> {
Log.e(TAG, "No Geofence Trigger Found! Abort mission!")
return
}
}

val notificationManager = ContextCompat.getSystemService(this, NotificationManager::class.java) as NotificationManager
notificationManager.handleNotification(this, fenceId)
}
}
}

companion object {
private const val TAG = "geofence-transitions"
private const val JOB_ID = 573

fun enqueueWork(context: Context, intent: Intent?) {
enqueueWork(context, GeofenceService::class.java, JOB_ID, intent!!)
}
}

这里是通知生成的代码

fun NotificationManager.handleNotification(context: Context, geofences: List<Geofence>){
val list = ArrayList<Notification>()
val set = mutableSetOf<Int>()
val notificationIdBase = (Date().time / 1000L % Int.MAX_VALUE).toInt()
this.apply {
for (i in geofences.indices){
val notificationId = notificationIdBase + i
val notification = createGroupNotification(context, notificationId, geofences[i].requestId)
list.add(notification)
notify(notificationId, notification)
set.add(notificationId)
Log.d("TAG", notificationId.toString())
}

Log.d("TAG", geofences.size.toString() + " " + list.size + " " + set.size)
for (id in set){
Log.d("TAG", id.toString())
}
}
}

这里是生成了 29 条通知但只有 24 条通知出现在手机上的案例的日志。

2020-05-04 16:46:32.944 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607192
2020-05-04 16:46:32.948 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607193
2020-05-04 16:46:32.952 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607194
2020-05-04 16:46:32.956 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607195
2020-05-04 16:46:32.958 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607196
2020-05-04 16:46:32.960 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607197
2020-05-04 16:46:32.965 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607198
2020-05-04 16:46:32.968 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607199
2020-05-04 16:46:32.971 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607200
2020-05-04 16:46:32.974 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607201
2020-05-04 16:46:32.977 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607202
2020-05-04 16:46:32.979 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607203
2020-05-04 16:46:32.981 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607204
2020-05-04 16:46:32.983 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607205
2020-05-04 16:46:32.985 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607206
2020-05-04 16:46:32.987 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607207
2020-05-04 16:46:32.990 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607208
2020-05-04 16:46:32.992 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607209
2020-05-04 16:46:32.994 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607210
2020-05-04 16:46:32.996 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607211
2020-05-04 16:46:32.998 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607212
2020-05-04 16:46:33.000 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607213
2020-05-04 16:46:33.002 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607214
2020-05-04 16:46:33.004 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607215
2020-05-04 16:46:33.005 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607216
2020-05-04 16:46:33.008 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607217
2020-05-04 16:46:33.009 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607218
2020-05-04 16:46:33.010 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607219
2020-05-04 16:46:33.012 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 1588607220
2020-05-04 16:46:33.012 31374-31459/com.superapps.ricardo.smithnotes D/TAG: 29 29 29

我什至尝试将它们分组到一个通知组中,但更多的通知消失了。

谢谢

最佳答案

正如 Tenfoure04 在评论中提到的,每个包的 notificationns 有一个硬性限制 ( https://github.com/aosp-mirror/platform_frameworks_base/blob/439ac26e6792b38deff4166dc7c1b35ddce18804/services/core/java/com/android/server/notification/NotificationManagerService.java#L291 )。

您可能面临的另一个问题是 android 对通知的 bundle 。类似的通知可能会被 bundle 在一起。只是尝试降低通知的频率。

关于Android 不显示所有通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61596369/

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