@Dmtm
Android

Почему нажатие на кнопку в нотификации не работает в А4.4, но работает в А7.0?

4.4 эмулятор, 7.0 - телефон
сервис
if (intent.action == ACTION_STOP_DOWNLOADING) {
            Log.d(TAG, "onStartCommand, ACTION_STOP_DOWNLOADING")
            mapLoaderBinder.stop()
        } else {
            Log.d(TAG, "onStartCommand, start foreground")
            val contentTitle = intent.getStringExtra(KEY_TITLE)
            val contentText = intent.getStringExtra(KEY_TEXT)

            val notificationIntent = Intent(this, MainActivity::class.java)
            val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)

            val notification = AppNotificationCompat.Builder(this, NotificationUtils.DOWNLOADING_MAP_CHANNEL_ID)
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setSmallIcon(R.drawable.ic_file_download)
                .setOngoing(true)
                .setContentIntent(pendingIntent)

            startForeground(1612, notification.build())
        }
        return START_STICKY
    }

в логах onStartCommand ACTION_STOP_DOWNLOADING вижу только после того как фоновая задача отработала, причем сразу все нажатия
визуально нажатие проходит, кнпока Stop мигает при нажатии
нотификация
fun showDownloadProgress(fileName: String, progressValue: Int) {
            val notificationBuilder = NotificationCompat.Builder(App.instance, DOWNLOADING_MAP_CHANNEL_ID)

            val contentIntent = Intent(App.instance, MainActivity::class.java)
            val contentPendingIntent = PendingIntent.getActivity(App.instance, 0, contentIntent, 0)

            val buttonCloseIntent = Intent(App.instance, MapLoadingService::class.java)
            buttonCloseIntent.action = MapLoadingService.ACTION_STOP_DOWNLOADING
            val buttonClosePendingIntent = PendingIntent.getService(App.instance, 0, buttonCloseIntent, PendingIntent.FLAG_UPDATE_CURRENT)
            val stopButtonAction = NotificationCompat.Action.Builder(R.drawable.ic_stop, "Stop", buttonClosePendingIntent).build()

            notificationBuilder
                .setSmallIcon(R.drawable.ic_file_download)
                .setPriority(Notification.PRIORITY_LOW)
                .setContentTitle("Loading map file")
                .setContentText(fileName)
                .setContentInfo(progressValue.toString())
                .setProgress(100, progressValue, false)
                //.setContentIntent(contentPendingIntent)
                .addAction(stopButtonAction)

            val notificationManager = App.instance.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
            notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, notificationBuilder.build())
        }
если добавить .setContentIntent(contentPendingIntent) то переключение на активность происходит сразу, а нажатия на кнопку в логах не появляются
  • Вопрос задан
  • 28 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы