skip to Main Content

I’m downloading a file through android DownloadManager with de function below.

 private fun downloadFile() {
        val downloadManager: DownloadManager =
            getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager

        val request =
            DownloadManager.Request(Uri.
            parse("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"))

        downloadManager.enqueue(request)
    }
}

The download occurs normally without any storage permissions.

Does the download manager work without storage permissions?
I can’t find the answer in the official documentation.

https://developer.android.com/reference/android/app/DownloadManager

2

Answers


  1. DownloadManager delegates the downloading work to a separate system-supplied app. That app has rights to write to a few locations, even if your app does not.

    Login or Signup to reply.
  2. If u use setDestinationInExternalPublicDir

    For applications targeting Build.VERSION_CODES.Q or above, WRITE_EXTERNAL_STORAGE permission is not needed and the dirType must be one of the known public directories like
    Environment#DIRECTORY_DOWNLOADS, Environment#DIRECTORY_PICTURES, Environment#DIRECTORY_MOVIES, etc.

    And for setDestinationUri

    For applications targeting Build.VERSION_CODES.Q or above, WRITE EXTERNAL_STORAGE permission is not needed and the uri must refer to a path within the directories owned by the application (e.g. Context#getExternalFilesDir(String)) or a path within the top-level Downloads directory (as returned by Environment#getExternalStoragePublicDirectory(String) with Environment#DIRECTORY_DOWNLOADS).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search