Answer the question
In order to leave comments, you need to log in
Why does clicking on a button in a notification not work in A4.4, but works in A7.0?
4.4 emulator, 7.0 - phone
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
}
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())
}
Answer the question
In order to leave comments, you need to log in
Everything turned out to be working, but, in my service, an observer is started on LiveData
App.instance.data.ftpDownloader.observeForever(ftpProgressObserver)
and when the files are downloaded, it is no longer needed and is deleted directly in it
private val ftpProgressObserver = Observer<CoroutineResultData<LoadingProgressFileData>> {
....
if (files.size > 0) {
val file = files.removeAt(0)
val client = App.instance.data.ftpClient.value
if (client?.data != null) {
App.instance.data.ftpDownloader.downloadFile(client.data, file)
}
} else {
Log.d(TAG, "before : NotificationUtils.hideDownloadProgress()")
NotificationUtils.hideDownloadProgress()
removeLoadingProgressObserver()
}
....
}
...
fun hideDownloadProgress() {
Log.d(TAG, "hideDownloadProgress() called")
....
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question