Created
December 18, 2013 17:01
-
-
Save sdecima/8025879 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
Great snippet. I use it as a Kotlin
Context
extension: