2

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

Community
  • 1
  • 1

1 Answers1

0

Two ways you can do this:

  1. Using pm disable command:

    Runtime runtime = Runtime.getRuntime();
    runtime.exec("pm disable "+packageName);
    
  2. Using PackageManager api:

    public abstract void setApplicationEnabledSetting (String packageName, 
                                                       int newState, int flags)
    

Where, in newState param you can pass "COMPONENT_ENABLED_STATE_DISABLED" to disable the app & "COMPONENT_ENABLED_STATE_ENABLED" to enable the app.

Ref: https://developer.android.com/reference/android/content/pm/PackageManager#setApplicationEnabledSetting(java.lang.String,%20int,%20int)

Sandip Pawar
  • 585
  • 4
  • 10