WEB开发网
开发学院手机开发Android 开发 Android应用客户端自动升级 阅读

Android应用客户端自动升级

 2010-08-26 00:18:00 来源:WEB开发网   
核心提示:int whichButton) {// 点击"取消"按钮之后退出程序}}).create();// 创建// 显示对话框dialog.show();}void downFile(final String url) {pBar.show();new Thread() {public void run

int whichButton) {

// 点击"取消"按钮之后退出程序

}

}).create();// 创建

// 显示对话框

dialog.show();

}

void downFile(final String url) {

pBar.show();

new Thread() {

public void run() {

HttpClient client = new DefaultHttpClient();

// params[0]代表连接的url

HttpGet get = new HttpGet(url);

HttpResponse response;

try {

response = client.execute(get);

HttpEntity entity = response.getEntity();

long length = entity.getContentLength();

InputStream is = entity.getContent();

FileOutputStream fileOutputStream = null;

if (is != null) {

File file = new File(Environment

.getExternalStorageDirectory(), "OA.apk");

fileOutputStream = new FileOutputStream(file);

byte[] buf = new byte[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();

}

down();

} catch (ClientProtocolException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}.start();

}

void down() {

handler.post(new Runnable() {

public void run() {

pBar.cancel();

update();

}

});

}

void update() {

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setDataAndType(Uri.fromFile(new File("/sdcard/OA.apk")),

"application/vnd.android.package-archive");

startActivity(intent);

}

}

上一页  1 2 

Tags:Android 应用 客户端

编辑录入:coldstar [复制链接] [打 印]
赞助商链接