How can I enable/disable a whole package programmatically from a Android System application?
In this post, a component is enabled/disabled programmatically, but not a whole package.
I want to achieve the same result that is achieved by the root command pm disable/enable package_name
(from the adb shell -> su).
答案 0 :(得分:0)
两种方法可以做到这一点:
使用pm disable命令:
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm disable "+packageName);
使用PackageManager API:
public abstract void setApplicationEnabledSetting (String packageName,
int newState, int flags)
在newState参数中,您可以传递“ COMPONENT_ENABLED_STATE_DISABLED”以禁用该应用程序,并传递“ COMPONENT_ENABLED_STATE_ENABLED”以启用该应用程序。