14

How do you enable and then disable a component from the manifest in the java code?

Dharman
  • 30,962
  • 25
  • 85
  • 135
scibor
  • 983
  • 4
  • 12
  • 21

1 Answers1

1

taking Pawan approach to more generic implementation:

public static void setComponentState(Context context, String packageName , String componentClassName, boolean enabled)
{
    PackageManager pm  = context.getApplicationContext().getPackageManager();
    ComponentName componentName = new ComponentName(packageName, componentClassName);
    int state = enabled ?  PackageManager.COMPONENT_ENABLED_STATE_ENABLED :  PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    pm.setComponentEnabledSetting(componentName,
            state,
            PackageManager.DONT_KILL_APP);

}
Noam Segev
  • 395
  • 3
  • 20