您的位置:首页 > 其它

安装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();
}
}

}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: