При попытке загрузить файл с помощью DownloadManager в Android SDK 22 я получаю эту ошибку:
java.lang.IllegalStateException: Unable to create directory: /storage/sdcard/Download
at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:538)
Приложение уже имеет разрешение WRITE_EXTERNAL_STORAGE
и при проверке оно возвращает true
Также работает при использовании эмулятора с SDK версии 25
val downloadManager = context.getSystemService(DOWNLOAD_SERVICE) as DownloadManager
val request = DownloadManager.Request(Uri.parse("https://xxxxxx.xx/public/App/xxx.apk"))
request.setDescription(context.getString(R.string.downloading_description)).setTitle(context.getString(R.string.app_name))
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "update.apk")
downloadManager.enqueue(request)
context.registerReceiver(onComplete, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
Этот код работает на SDK 25