Jimmy
Jimmy

Reputation: 583

DownloadManager: download a file to cache partition

I am using the public api of class DownloadManager, I am able to download files to sdcard, so-called external storage. However, when I tried to download a file to other places, like /cache partition, it throw a security exception which says "Destination must be on external storage".

Does anyone know how to bypass this limitation and write downloaded file to /cache partition ?

Thanks a lot.

Upvotes: 4

Views: 5450

Answers (2)

Brian R
Brian R

Reputation: 31

If you're developing a system app, there is a hidden function on DownloadManager.Request named setDestinationToSystemCache()

It requires these permissions:

android.permission.ACCESS_DOWNLOAD_MANAGER
android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED"
android.permission.ACCESS_CACHE_FILESYSTEM

Upvotes: 3

Jimmy
Jimmy

Reputation: 583

Actually I found a way to download files to /cache partition. In the DownloadManager class, there is an api setDestinationUri(), call this function with parameter "null", the android would download files to /cache partition. Moreover, if the parameter is not null, the uri must start with "/mnt/sdcard/..." otherwise an exception would be thrown.

Upvotes: 1

Related Questions