3

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

ColdFire
  • 6,764
  • 6
  • 35
  • 51
Konrad
  • 157
  • 1
  • 3
  • 10
  • Possible duplicate of [Caused by: java.lang.IllegalStateException: Unable to create directory in Android 6.0 devices](https://stackoverflow.com/questions/35767923/caused-by-java-lang-illegalstateexception-unable-to-create-directory-in-androi) – Arpan Sarkar Apr 24 '18 at 15:33
  • @Arpanßløødyßadßøy But I have both read and write permissions for the external storage (with permission a permission test that returns true) – Konrad Apr 24 '18 at 15:42
  • @Konrad You've requested the permissions at runtime? – earthw0rmjim Apr 24 '18 at 16:14
  • @earthw0rmjim Exactly: When checking it returns true (WRITE & READ) – Konrad Apr 24 '18 at 16:16

0 Answers0