Android DownloadManager and SSL (https)

北慕城南 提交于 2019-11-30 08:16:48

I had the same problem previously. Yup I see HTTPS support is already in ICS, but not in 2.3.7 and below, but we can extract the source code to create a DownloadManager to support that.

Based on the sample code from http://android-er.blogspot.com/2011/07/sample-code-using-androidappdownloadman.html i made a demo with extracted DownloadManager to support HTTPS.

You can find the sample code here https://github.com/alvinsj/android-https-downloadmanager-demo, run by just changing the url to your https based url.

Yes it seems that DownloadManager only supports HTTP protocol: http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/core/java/android/app/DownloadManager.java&exact_package=android&q=Can%20only%20download%20HTTP%20URIs&type=cs&l=343

I'm disappointed too as I just wanted to use it on a HTTPS site.

I've found a very easy solution for this:

request = new DownloadManager.Request(sourceUrl.replace("https://", "http://"))

Surprisingly worked for all https URLs that I tried. I'm not sure about the https security, but there is no exception and file gets downloaded properly.

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