1. 使用PM命令:
try {
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm disable " + "com.example.disableapp1");
} catch (Exception e) {
e.getStackTrace();
}
2.调用PackageManager的setApplicationEnabledSetting方法
public static void disableApplication(Context context){
PackageManager mPackageManager=context.getPackageManager();
mPackageManager.setApplicationEnabledSetting(applicationName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);
}
具体参数可见android官方文档: