Example usage for android.content.pm PackageManager COMPONENT_ENABLED_STATE_DISABLED

List of usage examples for android.content.pm PackageManager COMPONENT_ENABLED_STATE_DISABLED

Introduction

In this page you can find the example usage for android.content.pm PackageManager COMPONENT_ENABLED_STATE_DISABLED.

Prototype

int COMPONENT_ENABLED_STATE_DISABLED

To view the source code for android.content.pm PackageManager COMPONENT_ENABLED_STATE_DISABLED.

Click Source Link

Document

Flag for #setApplicationEnabledSetting(String,int,int) and #setComponentEnabledSetting(ComponentName,int,int) : This component or application has been explicitly disabled, regardless of what it has specified in its manifest.

Usage

From source file:Main.java

public static void disableComponent(PackageManager pm, ComponentName component) {
    pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:Main.java

public static boolean isEnabled(Context context, Class<?> clazz) {
    ComponentName componentName = new ComponentName(context, clazz);
    PackageManager pm = context.getPackageManager();
    return pm.getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}

From source file:Main.java

public static void setHideApplication(Context c, boolean hide) {
    ComponentName cn = new ComponentName(c.getApplicationContext(), ALIAS_CLASSNAME);
    int setting = hide ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
            : PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    int current = c.getPackageManager().getComponentEnabledSetting(cn);
    if (current != setting) {
        c.getPackageManager().setComponentEnabledSetting(cn, setting, PackageManager.DONT_KILL_APP);
    }//  w  ww.  ja  v  a 2s  . c om
}

From source file:Main.java

public static void setComponentEnabled(Class<?> componentClass, boolean enabled, Context context) {
    ComponentName componentName = new ComponentName(context, componentClass);
    PackageManager packageManager = context.getPackageManager();
    int state = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    packageManager.setComponentEnabledSetting(componentName, state, PackageManager.DONT_KILL_APP);
}

From source file:Main.java

public static void toggleComponent(Context context, Class componentClass, boolean state) {
    ComponentName componentName = new ComponentName(context, componentClass);
    context.getPackageManager().setComponentEnabledSetting(componentName,
            state ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:Main.java

public static void setComponentEnabled(PackageManager packageManager, Context context, Class<?>[] classes,
        boolean enabled) {
    int length = classes.length;
    for (int i = 0; i < length; i++) {
        Class<?> clazz = classes[i];
        final ComponentName c = new ComponentName(context, clazz.getName());
        packageManager.setComponentEnabledSetting(c, enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }//  w w  w  .  ja v  a  2 s .c o  m
}

From source file:Main.java

/**
 * Enable/Disable Broadcast Receiver/*from ww  w  .j a  v  a2s.  c  om*/
 *
 * @param context
 *     the context
 * @param brClass
 *     the br class
 * @param enabled
 *     the enabled
 */
public static void setStateOfReceiver(Context context, Class<?> brClass, boolean enabled) {
    ComponentName receiverName = new ComponentName(context, brClass.getName());
    PackageManager pm = context.getPackageManager();

    int newstate;
    if (enabled) {
        newstate = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    } else {
        newstate = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }

    pm.setComponentEnabledSetting(receiverName, newstate, PackageManager.DONT_KILL_APP);
}

From source file:Main.java

public static void toggleAppIcon(Context context, boolean newState) {
    ComponentName componentName = new ComponentName("com.noshufou.android.su", "com.noshufou.android.su.Su");
    context.getPackageManager().setComponentEnabledSetting(componentName,
            newState ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:Main.java

/**
 * Disable broadcast received component.
 * @param c//ww  w  .java  2  s .c  om
 * @param component
 */
public static void disableReceiver(Context c, Class component) {
    ComponentName receiver = new ComponentName(c, component);
    PackageManager pm = c.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.kaliturin.blacklist.utils.DefaultSMSAppHelper.java

public static void enableSMSReceiving(Context context, boolean enable) {
    int state = (enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
    PackageManager packageManager = context.getPackageManager();
    ComponentName componentName = new ComponentName(context, SMSBroadcastReceiver.class);
    packageManager.setComponentEnabledSetting(componentName, state, PackageManager.DONT_KILL_APP);
}