Example usage for android.content.pm PackageManager COMPONENT_ENABLED_STATE_ENABLED

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

Introduction

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

Prototype

int COMPONENT_ENABLED_STATE_ENABLED

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

Click Source Link

Document

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

Usage

From source file:com.lee.sdk.utils.Utils.java

/**
 * component??//from w w w . ja  va 2  s  .  c om
 * 
 * @param ctx context
 * @param className class name
 * @return ??
 */
public static boolean isComponentEnable(Context ctx, String className) {
    PackageManager pm = ctx.getPackageManager();
    ComponentName cn = new ComponentName(ctx.getPackageName(), className);
    int ret = pm.getComponentEnabledSetting(cn);
    if (ret == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            || ret == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
        return true;
    }
    return false;
}

From source file:com.air.mobilebrowser.BrowserActivity.java

/**
 * Clear the setting for default home./* w w w .j a  va 2 s  .  c o  m*/
 */
private void clearHome() {
    PackageManager pm = getPackageManager();

    ComponentName fauxHomeComponent = new ComponentName(getApplicationContext(), FauxHome.class);
    ComponentName homeComponent = new ComponentName(getApplicationContext(), BrowserActivity.class);

    pm.setComponentEnabledSetting(fauxHomeComponent, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
    pm.setComponentEnabledSetting(homeComponent, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
    pm.setComponentEnabledSetting(fauxHomeComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
    pm.setComponentEnabledSetting(homeComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.ichi2.anki.PreferenceContext.java

/**
 * Code which is run when a SharedPreference change has been detected
 * @param prefs instance of SharedPreferences
 * @param key key in prefs which is being updated
 * @param listener PreferenceActivity of PreferenceFragment which is hosting the preference
 *///from  www .ja v a2  s. co  m
private void updatePreference(SharedPreferences prefs, String key, PreferenceContext listener) {
    try {
        PreferenceScreen screen = listener.getPreferenceScreen();
        Preference pref = screen.findPreference(key);
        // Handle special cases
        switch (key) {
        case "timeoutAnswer": {
            CheckBoxPreference keepScreenOn = (CheckBoxPreference) screen.findPreference("keepScreenOn");
            keepScreenOn.setChecked(((CheckBoxPreference) pref).isChecked());
            break;
        }
        case LANGUAGE:
            closePreferences();
            break;
        case "convertFenText":
            if (((CheckBoxPreference) pref).isChecked()) {
                ChessFilter.install(Hooks.getInstance(getApplicationContext()));
            } else {
                ChessFilter.uninstall(Hooks.getInstance(getApplicationContext()));
            }
            break;
        case "fixHebrewText":
            if (((CheckBoxPreference) pref).isChecked()) {
                HebrewFixFilter.install(Hooks.getInstance(getApplicationContext()));
                showDialog(DIALOG_HEBREW_FONT);
            } else {
                HebrewFixFilter.uninstall(Hooks.getInstance(getApplicationContext()));
            }
            break;
        case "showProgress":
            getCol().getConf().put("dueCounts", ((CheckBoxPreference) pref).isChecked());
            getCol().setMod();
            break;
        case "showEstimates":
            getCol().getConf().put("estTimes", ((CheckBoxPreference) pref).isChecked());
            getCol().setMod();
            break;
        case "newSpread":
            getCol().getConf().put("newSpread", Integer.parseInt(((ListPreference) pref).getValue()));
            getCol().setMod();
            break;
        case "timeLimit":
            getCol().getConf().put("timeLim", ((NumberRangePreference) pref).getValue() * 60);
            getCol().setMod();
            break;
        case "learnCutoff":
            getCol().getConf().put("collapseTime", ((NumberRangePreference) pref).getValue() * 60);
            getCol().setMod();
            break;
        case "useCurrent":
            getCol().getConf().put("addToCur", ((ListPreference) pref).getValue().equals("0"));
            getCol().setMod();
            break;
        case "dayOffset": {
            int hours = ((SeekBarPreference) pref).getValue();
            Timestamp crtTime = new Timestamp(getCol().getCrt() * 1000);
            Calendar date = GregorianCalendar.getInstance();
            date.setTimeInMillis(crtTime.getTime());
            date.set(Calendar.HOUR_OF_DAY, hours);
            getCol().setCrt(date.getTimeInMillis() / 1000);
            getCol().setMod();
            break;
        }
        case "minimumCardsDueForNotification": {
            ListPreference listpref = (ListPreference) screen.findPreference("minimumCardsDueForNotification");
            if (listpref != null) {
                updateNotificationPreference(listpref);
            }
            break;
        }
        case "reportErrorMode": {
            String value = prefs.getString("reportErrorMode", "");
            AnkiDroidApp.getInstance().setAcraReportingMode(value);
            break;
        }
        case "syncAccount": {
            SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
            String username = preferences.getString("username", "");
            Preference syncAccount = screen.findPreference("syncAccount");
            if (syncAccount != null) {
                if (TextUtils.isEmpty(username)) {
                    syncAccount.setSummary(R.string.sync_account_summ_logged_out);
                } else {
                    syncAccount.setSummary(getString(R.string.sync_account_summ_logged_in, username));
                }
            }
            break;
        }
        case "providerEnabled": {
            ComponentName providerName = new ComponentName(this, "com.ichi2.anki.provider.CardContentProvider");
            PackageManager pm = getPackageManager();
            int state;
            if (((CheckBoxPreference) pref).isChecked()) {
                state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
                Timber.i("AnkiDroid ContentProvider enabled by user");
            } else {
                state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
                Timber.i("AnkiDroid ContentProvider disabled by user");
            }
            pm.setComponentEnabledSetting(providerName, state, PackageManager.DONT_KILL_APP);
            break;
        }
        }
        // Update the summary text to reflect new value
        updateSummary(pref);
    } catch (BadTokenException e) {
        Timber.e(e, "Preferences: BadTokenException on showDialog");
    } catch (NumberFormatException | JSONException e) {
        throw new RuntimeException();
    }
}

From source file:com.android.purenexussettings.TinkerActivity.java

public void setLauncherIconEnabled(boolean enabled) {
    int newState;
    PackageManager packman = getPackageManager();
    if (enabled) {
        newState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    } else {//w  ww  .j  a v a2  s.c o  m
        newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }
    packman.setComponentEnabledSetting(new ComponentName(this, LauncherActivity.class), newState,
            PackageManager.DONT_KILL_APP);
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Enables the component status of an Activity. If the activity has the
 * android.intent.category.LAUNCHER intent, it will add the launcher icon
 * in the applications menu./*from   w  w w  .j a v a2  s .  co  m*/
 *
 * @param context   The application context
 * @param appClass  Class of the activity
 */
public static void application_activityEnable(Context context, Class appClass) {
    application_activityStatusSwitch(context, appClass, PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

private static void application_activityStatusSwitch(Context context, Class appClass, int status) {
    ComponentName component = new ComponentName(appClass.getPackage().getName(), appClass.getName());

    if (status == PackageManager.COMPONENT_ENABLED_STATE_DISABLED && (context.getPackageManager()
            .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            || context.getPackageManager()
                    .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)) {
        context.getPackageManager().setComponentEnabledSetting(component,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

    } else if (status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED && (context.getPackageManager()
            .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
            || context.getPackageManager()
                    .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)) {
        context.getPackageManager().setComponentEnabledSetting(component,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    }//from w  w  w.  j  a  va2  s .c om
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Enables the component status of an Activity Alias. If the activity alias points to an
 * Activity with android.intent.category.LAUNCHER intent, it will add the launcher icon
 * in the applications menu.//w w  w  .  j a  v  a2s  . co m
 *
 * @param context
 * @param appClass
 * @param appLaunchAlias
 */
public static void application_activityAliasEnable(Context context, Class appClass, String appLaunchAlias) {
    application_activityAliasStatusSwitch(context, appClass, appLaunchAlias,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
}

From source file:org.getlantern.firetweet.service.BackgroundOperationService.java

private void triggerEasterEgg(boolean notReplyToOther, boolean hasEasterEggTriggerText,
        boolean hasEasterEggRestoreText) {
    final PackageManager pm = getPackageManager();
    final ComponentName main = new ComponentName(this, MainActivity.class);
    final ComponentName main2 = new ComponentName(this, MainHondaJOJOActivity.class);
    if (hasEasterEggTriggerText && notReplyToOther) {
        pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
        pm.setComponentEnabledSetting(main2, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
        showToast(R.string.easter_egg_triggered_message, Toast.LENGTH_SHORT);
    } else if (hasEasterEggRestoreText) {
        pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
        pm.setComponentEnabledSetting(main2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
        showToast(R.string.icon_restored_message, Toast.LENGTH_SHORT);
    }/*w  w w .ja v  a2 s.  co m*/
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Switches the component status of an Activity Alias. Use this to enable or disable it. If the
 * activity alias points to an Activity with android.intent.category.LAUNCHER intent, it will
 * remove/add the launcher icon in the applications menu.
 *
 * @param context           The application context
 * @param appClass          Class of the activity alias
 * @param appLaunchAlias    The android:name of the activity-alias entry in the manifest.
 *//*from   w ww.  j a v a 2  s . c  o  m*/
public static void application_activityAliasSwitchStatus(Context context, Class appClass,
        String appLaunchAlias) {
    ComponentName component = new ComponentName(appClass.getPackage().getName(),
            appClass.getPackage().getName() + "." + appLaunchAlias);
    if (context.getPackageManager()
            .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
        application_activityAliasStatusSwitch(context, appClass, appLaunchAlias,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
    } else if (context.getPackageManager()
            .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
        application_activityAliasStatusSwitch(context, appClass, appLaunchAlias,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
    }
}