小弟在这里介绍一种很笨的办法
把你关联的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);
}
各位如果有什么更好的方法的话,请分享出来 大家一起学习