Forked from sdecima/Android_enableManifestComponent.java
Created
November 14, 2017 10:04
-
-
Save ok3141/ab43a3300533d133c1c9d13fa535d579 to your computer and use it in GitHub Desktop.
How to dynamically enable/disable an Android Component declared in the manifest.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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