I have made a download method that works fine. It takes a String url and returns the downloaded InputStream which gets processed by XMLPullParser. Now I want to add a progressbar to the download. I have figured out that I can somehow use getContentLength() on HttpURLConnection but I do not know how to calculate the progressbar after that.
This is my code:
public static InputStream downloadUrl(String urlString) throws IOException {
    URL url = new URL(urlString);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(15000);
    conn.setConnectTimeout(25000);
    conn.setRequestMethod("GET");
    conn.setDoInput(true);
    conn.setUseCaches(true);
    conn.setRequestProperty("Content-Type", "application/xml; charset=utf-8");
    conn.setRequestProperty("Accept", "application/xml");
    conn.connect();
    int size = conn.getContentLength();
    InputStream stream = conn.getInputStream();
            //calculate the progress
    return stream;      
}
Thanks!
 
     
    