Example usage for android.content.pm PackageManager DONT_KILL_APP

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

Introduction

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

Prototype

int DONT_KILL_APP

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

Click Source Link

Document

Flag parameter for #setComponentEnabledSetting(android.content.ComponentName,int,int) to indicate that you don't want to kill the app containing the component.

Usage

From source file:Main.java

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

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 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(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 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);
    }/*from  w  w  w  .ja  v  a  2  s .  co m*/
}

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);
    }//from   www .ja v  a2s  .c  o  m
}

From source file:Main.java

/**
 * Enable/Disable Broadcast Receiver/*w  w w .  j a v  a 2s .c  o m*/
 *
 * @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

/**
 * Enable broadcast received component.//w w w.  j a  v  a2  s. c  om
 * @param c
 * @param component
 */
public static void enableReceiver(Context c, Class component) {
    ComponentName receiver = new ComponentName(c, component);
    PackageManager pm = c.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:Main.java

/**
 * Disable broadcast received component.
 * @param c// ww w  . j a  v a 2s .  c o m
 * @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);
}