Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the proxy for android's DownloadManager class

Tags:

android

proxy

I have an app with a WebView, which downloads videos and plays them in a VideoView.

To manage the downloads I use android's handy DownloadManager API. Unfortunately in some situations I need to use a proxy.

I have successfully set up the proxy for the WebView using reflection as detailed in this stackoverflow question, but I am not sure how I can set the DownloadManager to use a proxy as well..

Is this possible? If not, what are my alternatives?

Thanks

like image 613
Ed_ Avatar asked Jan 20 '14 20:01

Ed_


1 Answers

I couldn't find a way to do this with the DownloadManager so I ended up implementing my own (simplified) download manager using an AsyncTask.

It's possible then to pass a Proxy object to Url.openConnection as below:

Proxy proxy = new Proxy(Proxy.Type.HTTP, 
                        new InetSocketAddress(proxyHost, proxyPort));
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);

Once you've got the proxied connection you can download content as per usual.

like image 52
Ed_ Avatar answered Oct 16 '22 14:10

Ed_