android 在程式碼中安裝apk的方法

weixin_34119545發表於2012-09-01

第一步:儲存apk檔案到sdcard或者其他地方

第二步:修改apk檔案的許可權為可執行 ,例如chmod ‘777’ file:

String command     = "chmod " + permission + " " + path;
Runtime runtime = Runtime.getRuntime();
runtime.exec(command);

 

第三步:使用Intent 呼叫安裝:

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);

相關文章