Why does the download manager require "WRITE_EXTERNAL_STORAGE" for maxSdkVersion> 18
I use Download managerto upload a file and save it to external storage as follows:
DownloadManager.Request req = new DownloadManager.Request(uri);
req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setDestinationInExternalFilesDir(TextReaderActivity.this, null, "podcasts/" + Integer.toString(article.id) + PODCAST_EXTENSION);
I get the following exception:
Exception: need WRITE_EXTERNAL_STORAGE permission to use DESTINATION_FILE_URI: uid 10052 does not have android.permission.WRITE_EXTERNAL_STORAGE.
I read that I do not need to ask permission WRITE_EXTERNAL_STORAGEfor maxSdkVersion > 18when writing to external directories, why doesn't it require it here with DownloadManager?
UPDATE:
In Android 4.4 and above, the rules are slightly different:
- to read or write trees embedded in getExternalFilesDir () and getExternalCacheDir () in the directory, you do not need permission
- To write to another location on external storage, you need WRITE_EXTERNAL_STORAGE
- To read from anywhere else on external storage, you need either WRITE_EXTERNAL_STORAGE (if you already have) or READ_EXTERNAL_STORAGE (if not)