android 在代碼中安裝apk的方法
第一步:保存apk文件到sdcard或者其他地方
第二步:修改apk文件的權(quán)限為可執(zhí)行 篇恒,例如chmod ‘777’ file:
String command = "chmod " + permission + " " + path;
Runtime runtime = Runtime.getRuntime();
runtime.exec(command);
第三步:使用Intent 調(diào)用安裝:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.parse("file://" + path),"application/vnd.android.package-archive");
context.startActivity(intent);