[java]
/**
* 下载文件
* @param url
*/
private void downFile(final String url) {
mProgressDialog = new ProgressDialog(activity)
mProgressDialogsetProgressStyle(ProgressDialogSTYLE_SPINNER)
mProgressDialogsetMessage(请等待…)
mProgressDialogshow()
new Thread() {
@Override
public void run() {
DefaultHttpClient client = new DefaultHttpClient()
HttpGet get = new HttpGet(url)
HttpResponse response;
try {
response = clientexecute(get)
HttpEntity entity = responsegetEntity()
long length = entitygetContentLength()
InputStream is = entitygetContent()
FileOutputStream fileOutputStream = null;
if (is != null) {
File file = new File(PATH + software + apk)
fileOutputStream = new FileOutputStream(file)
byte[] buf = new byte[];
int ch = ;
int count = ;
while ((ch = isread(buf)) != ) {
// baoswrite(buf ch)
fileOutputStreamwrite(buf ch)
count += ch;
if (length > ) {
}
}
}
fileOutputStreamflush()
if (fileOutputStream != null) {
fileOutputStreamclose()
}
update()
} catch (ClientProtocolException e) {
eprintStackTrace()
} catch (IOException e) {
eprintStackTrace()
}
}
}start()
}
private void update() {
//Logv(update update)
Intent intent = new Intent(IntentACTION_VIEW)
intentsetDataAndType(
UrifromFile(new File(file:// + PATH + software + apk))
application/vndandroidpackagearchive)
activitystartActivity(intent)
}