问题
Well I am trying to download file via download manager my url adress starts as:
https://dl.dropbox.com...
it is working fine on android 4.1.2 or others. but it gives error at android 2.3.3 and this log cat
java.lang.IllegalArgumentException: Can only download HTTP URIs: https://dl.dropbox.com/s/jcy3ahcauj7gu...
at android.app.DownloadManager$Request.(DownloadManager.java:440)
回答1:
Update Nov. 2019: You shouldn't have this problem nowadays with minSdkVersion being at least API 19, the native DownloadManager
should support https
just fine. This was different in the Android 2.x era.
Original answer:
Replacing https
for http
in the URL
is not the solution as it's often suggested. There is no guarantee that the same resource is served in plain http
.
What I found to be the best, is backporting the DownloadManager by adding it to your sources. There are mainly two classes that you will need: DownloadMananger & Downloads. You will have to do a few changes to the sources, like changing the package name and using DownloadManager's constructor directly instead of using getSystemService(DOWNLOAD_SERVICE)
.
This way you get the functionality without compromising on older devices. If you want, you may conditionally decide whether to use the native implementation or the one provided in your sources, depending on the version of Android the device is running.
Someone already did this with a slightly older version, check his github.
来源:https://stackoverflow.com/questions/24147934/android-download-manager-can-only-download-http-uris