Android Download manager Can only download HTTP URIs:

余生颓废 提交于 2019-12-13 16:58:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!