小弟在这里介绍一种很笨的办法
把你关联的apk放在 assets目录下面。代码如下,只是在安装关联apk的时候是显示安装的。
private File getAssetFile(){
AssetManager asset = MainActivity.this.getAssets();
InputStream is = asset.open("Zxing.apk");
FileOutputStream fos =
this.openFileOutput("Zxing.apk",Context.MODE_PRIVATE+Context.MODE_WORLD_READABLE);
byte[] buffer = new byte[1024];
int len = 0;
while((len=is.read(buffer))!=-1){
fos.write(buffer, 0, len)
}
fos.flush();
is.close();
fos.close();
return new File("Zxing.apk");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void installApk(File file){
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
String type = "android/vnd.android.package-archive";
intent .setDataAndType(Uri.from(file),type);
startActivity(intent);
}
各位如果有什么更好的方法的话,请分享出来 大家一起学习
本文介绍了如何在Android应用中将关联的APK放在assets目录下,并在安装主应用时一同安装这些关联的APK。通过AssetManager读取APK文件,然后写入到私有文件存储区,最后使用Intent启动安装过程。

被折叠的 条评论
为什么被折叠?



