安装ASSETS下的APK,(拷贝到本地安装)
2016-07-28 17:43
393 查看
/** * 安装APK的方法,弹窗系统安装 * @param index */ private void installApk(int index) { createFile(); File fileUrl= new File(Environment.getExternalStorageDirectory().getPath() + "/temp"+index+".apk"); System.out.println("-------------->"+fileUrl.toString()); Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(fileUrl), "application/vnd.android.package-archive"); startActivity(intent); } /** * 复制assets下的安装包到本地 */ public void createFile() { String [] apps ={"developer","DeviceInfoCollect","xbfile","yingyongguanli"}; for(int j = 0; j < apps.length; j++){ System.out.print(apps[j] + " "); InputStream is = null; FileOutputStream fos = null; try { is = MainActivity.this.getAssets().open(apps[j]+".apk"); File file = new File(Environment.getExternalStorageDirectory() .getPath() + "/temp"+j+".apk"); file.createNewFile(); fos = new FileOutputStream(file); byte[] temp = new byte[1024]; int i = 0; while ((i = is.read(temp)) > 0) { fos.write(temp, 0, i); } System.out.println("-------->拷贝成功"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
相关文章推荐
- IOS-- UIView中的坐标转换
- centos5 下 lida 调试环境搭建
- 有关浏览器兼容问题
- 通信时地址的简单设置
- AngularJS 所有版本下载
- 【jQuery】纯js的右下角弹窗
- RNN以及LSTM的介绍和公式梳理
- 【hdu 2795】Billboard 【线段树训练 3】
- 开发代理 AFNetworking 解析失败
- 关于出现Unhandled exception at 0x091f11c7 in ****: 0xC0000005: Access violation reading location 0x0ab0f
- 基于口令和证书认证(TrueLicense)的接口调用工具库的封装设计 By 嗡汤圆
- java通过jni调用c++
- EditText
- bzoj1066(网络流)
- Android4.2 Usb Debug启动流程
- sublime中安装sublimelinter php 语法检查
- java项目转换依赖等问题
- java-设计模式-观察者模式
- 解决Ubuntu中使用windows文件名乱码问题
- iOS 实现时间线列表效果