[Java]
/**
* Download an object
* @ Param url
*/
Private void downFile (final String url ){
MProgressDialog = new ProgressDialog (activity );
MProgressDialog. setProgressStyle (ProgressDialog. STYLE_SPINNER );
MProgressDialog. setMessage ("Please wait ...");
MProgressDialog. show ();
New Thread (){
@ Override
Public void run (){
DefaultHttpClient client = new DefaultHttpClient ();
HttpGet = new HttpGet (url );
HttpResponse response;
Try {
Response = client.exe cute (get );
HttpEntity entity = response. getEntity ();
Long length = entity. getContentLength ();
InputStream is = entity. getContent ();
FileOutputStream fileOutputStream = null;
If (is! = Null ){
File file = new File (PATH + software + ". apk ");
FileOutputStream = new FileOutputStream (file );
Byte [] buf = new byte [1, 1024];
Int ch =-1;
Int count = 0;
While (ch = is. read (buf ))! =-1 ){
// Baos. write (buf, 0, ch );
FileOutputStream. write (buf, 0, ch );
Count + = ch;
If (length> 0 ){
}
}
}
FileOutputStream. flush ();
If (fileOutputStream! = Null ){
FileOutputStream. close ();
}
Update ();
} Catch (ClientProtocolException e ){
E. printStackTrace ();
} Catch (IOException e ){
E. printStackTrace ();
}
}
}. Start ();
}
Private void update (){
// Log. v ("update", "update ");
Intent intent = new Intent (Intent. ACTION_VIEW );
Intent. setDataAndType (
Uri. fromFile (new File ("file: //" + PATH + software + ". apk ")),
"Application/vnd. android. package-archive ");
Activity. startActivity (intent );
}