Android 9 doesn't show the notification bar when downloading files in my app

82 views Asked by At

I am developing an application where file downloads are performed, I already tried on several devices the download and the notifier works fine at the top, but for some reason, in android 9 the notifier is not shown, however if the application is downloaded, I do not know what it could be, I already tried and I do not give, if someone can help me please, I attach the method that performs the download

web_view?.setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
    urlFile = url
    mimeTypeFile = mimetype
    contentDispositionFile = contentDisposition
    downloadingFile = true
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(activity!!, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 0)
        } else{
            downloadFile()
        }
    } else {
        downloadFile()
    }   
}

fun downloadFile() {
    val request = DownloadManager.Request(Uri.parse(urlFile))
    request.setDescription("Descargando archivo...")
    val fileName = URLUtil.guessFileName(urlFile, contentDispositionFile, mimeTypeFile)
    request.setTitle(fileName)
    request.allowScanningByMediaScanner()
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
    request.setVisibleInDownloadsUi(true)
    request.setDestinationInExternalPublicDir(getDirectoryDownload(), fileName)
    val dManager = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
    downloadingFile = false
    dManager.enqueue(request)
}
0

There are 0 answers