When trying to download a file with DownloadManager in Android sdk 22 I get this error:
java.lang.IllegalStateException: Unable to create directory: /storage/sdcard/Download
at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:538)
The app already has the permission WRITE_EXTERNAL_STORAGE
and when checking for it it returns true
It also works when using an emulator with sdk version 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))
This code works on sdk 25