Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ok3141/ab43a3300533d133c1c9d13fa535d579 to your computer and use it in GitHub Desktop.
Save ok3141/ab43a3300533d133c1c9d13fa535d579 to your computer and use it in GitHub Desktop.
How to dynamically enable/disable an Android Component declared in the manifest.
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
public class Android_enableManifestComponent {
public static void enableManifestComponent(Context context, Class<?> component, boolean enable) {
ComponentName receiver = new ComponentName(context, component);
PackageManager pm = context.getPackageManager();
int newState = (enable ?
PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
pm.setComponentEnabledSetting(receiver, newState,
PackageManager.DONT_KILL_APP);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment