apk 下载
關于apk下載的一些問題
獲取本地的版本號和服務器的版本號進行版本控制
連接服務器apk地址進行下載
ProgressDialog dialog = ProgressDialog.show(MainActivity2.this, "提示", "正在下載中", false, false);downloadApk(dialog); public void downloadApk(final ProgressDialog dialog ){new Thread() {public void run() {HttpClient httpClient = new DefaultHttpClient();HttpGet httpGet = new HttpGet(pref.getString(Constant.Preference.SERVER)+Constant.Url.DOWN);HttpParams httpParams = httpClient.getParams();HttpConnectionParams.setConnectionTimeout(httpParams, 5000);HttpConnectionParams.setSoTimeout(httpParams, 5000);HttpResponse httpResponse = null;try {httpResponse = httpClient.execute(httpGet);HttpEntity httpEntity = httpResponse.getEntity();if (httpEntity != null) {InputStream is = httpEntity.getContent();File dir = new File(Environment.getExternalStorageDirectory()+ MyConfig.DOWNLOADPATH);if (!dir.exists()) {dir.mkdir();}File file = new File(Environment.getExternalStorageDirectory()+ MyConfig.DOWNLOADPATH,MyConfig.DOWNLOADAPK);FileOutputStream fileOutputStream = new FileOutputStream(file);byte[] buff = new byte[1024];int ch = -1;while ((ch = is.read(buff)) != -1) {fileOutputStream.write(buff, 0, ch);}fileOutputStream.flush();fileOutputStream.close();is.close();}handler.sendEmptyMessage(MyConfig.MSG_APKINSTALL);dialog.dismiss();} catch (Exception e) {// TODO Auto-generated catch blockLog.d("NetWorkUtils--->downApk---catch exception is ", e.getMessage());e.printStackTrace(); // handler.sendEmptyMessage(MyConfig.MSG_DOWNLOADAPK_FAIL);}}}.start();下載完成后安裝apk
Intent intent = new Intent(Intent.ACTION_VIEW); //MyConfig.DOWNLOADPATH 下載的apk存放文件將夾 "/jdjianxiu/" //MyConfig.DOWNLOADAPK apk的名稱 intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+ MyConfig.DOWNLOADPATH ,MyConfig.DOWNLOADAPK)),"application/vnd.android.package-archive");startActivity(intent);總結
- 上一篇: 注册表修改备用dns服务器地址,备用dn
- 下一篇: FLUENT: turbulent vi