在Android系统开发过程中,有第三方App开发需要静默安装和卸载。纯App必须需要root权限,还要通过反射(相关接口被隐藏了)去调用,有些麻烦。自己就写了个App(SilentInstaller),实现静默安装和卸载,调用代码简洁,无需任何权限。
下面贴下静默安装和卸载代码:
private void silentInstall(String path) {
File apkFile = new File(path);
if (!apkFile.exists()) {
mH.sendMessage(mH.obtainMessage(HANDLER_SHOW_MESSAGE,
String.format(getString(R.string.apk_file_not_exist), path)));
Log.e(TAG, "silentInstall " + path + " is not exists!");
return;
}
Uri uri = Uri.fromFile(new File(path));
String packa