Android не отображаются все уведомления - PullRequest
1 голос
/ 04 мая 2020

Я создал приложение, которое может отправлять много уведомлений одновременно, проблема в том, что если количество уведомлений больше, чем, например, 6 или 7, не все уведомления отображаются, несмотря на то, что в журнале говорится, что все уведомления были созданы и имеют уникальные идентификаторы.

вот код службы для уведомлений

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

Я даже попытался сгруппировать их в группу уведомлений, но еще больше уведомлений исчезло.

Спасибо

...