URL url = newurl (http://somewhere.com/some/webhosted/file);
Httpurlconnectionurlconnection = (httpurlconnection)url.openconnection ();
Urlconnection.setrequestmethod ("GET");
Urlconnection.setdooutput (TRUE);
Urlconnection.connect ();
File sdcardroot = Environment.getexternalstoragedirectory ();
File File = new file (sdcardroot, "Somefile.ext");
FileOutputStream fileOutput = new FileOutputStream (file);
InputStream InputStream =Urlconnection.getinputstream ();
int totalsize =urlconnection.getcontentlength ();
Pd.setmax(totalsize);//progressdialog PD
int downloadedsize = 0;
byte[] buffer = new byte[1024];
int bufferlength = 0;
while ((Bufferlength = inputstream.read (buffer)) > 0) {
Fileoutput.write (buffer, 0, bufferlength);
Downloadedsize + = Bufferlength;
pd.setprogress(downloadedsize);//progressdialog PD
}
Progress bar tips for Android download files (network communication section example)