第一种:
try {
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm disable " + “com.example.disableapp1”);
} catch (Exception e) {
e.getStackTrace();
}
adb shell pm enable com.example.disableapp1
第二种:
public static void disableApplication(Context context){
android.content.pm.PackageManager mPackageManager=context.getPackageManager();
mPackageManager.setApplicationEnabledSetting(applicationName,android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED,android.content.pm.PackageManager.DONT_KILL_APP);
}
public static void enableApplication(android.content.Context context){
android.content.pm.PackageManager mPackageManager=context.getPackageManager();
mPackageManager.setApplicationEnabledSetting(applicationName, android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED, android.content.pm.PackageManager.DONT_KILL_APP);
}
本文介绍了在Java中使用Runtime类和adb命令行以及Android应用程序管理API来禁用和启用应用的方法,包括Runtime.getRuntime().exec()和PackageManager的setApplicationEnabledSetting()函数.
5万+

被折叠的 条评论
为什么被折叠?



