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:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.menu_run_intent:
        runIntent();/*from w w  w. j  ava 2  s. c  o m*/
        return true;
    case R.id.set_editor_result:
        updateIntent();
        setResult(0, new Intent().putExtra(Editor.EXTRA_VALUE, mEditedIntent));
        finish();
        return true;
    case R.id.attach_intent_filter: {
        // We have specified component, just find IntentFilters for it
        final ComponentName componentName = mEditedIntent.getComponent();
        ExtendedPackageInfo.getExtendedPackageInfo(this, componentName.getPackageName(),
                new ExtendedPackageInfo.Callback() {
                    @Override
                    public void onPackageInfoAvailable(ExtendedPackageInfo extendedPackageInfo) {
                        try {
                            setAttachedIntentFilters(extendedPackageInfo
                                    .getComponentInfo(componentName.getClassName()).intentFilters);
                            Toast.makeText(IntentEditorActivity.this, R.string.intent_filter_attached,
                                    Toast.LENGTH_SHORT).show();
                        } catch (NullPointerException e) {
                            Toast.makeText(IntentEditorActivity.this, R.string.no_intent_filters_found,
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }

        return true;
    case R.id.detach_intent_filter:
        clearAttachedIntentFilters();
        return true;
    case R.id.component_info: {
        ComponentName component = mEditedIntent.getComponent();
        startActivity(new Intent(this, SingleFragmentActivity.class)
                .putExtra(SingleFragmentActivity.EXTRA_FRAGMENT, ComponentInfoFragment.class.getName())
                .putExtra(ComponentInfoFragment.ARG_PACKAGE_NAME, component.getPackageName())
                .putExtra(ComponentInfoFragment.ARG_COMPONENT_NAME, component.getClassName())
                .putExtra(ComponentInfoFragment.ARG_LAUNCHED_FROM_INTENT_EDITOR, true));
    }
        return true;
    case R.id.save: {
        updateIntent();
        SavedItemsDatabase.getInstance(this).saveIntent(this, mEditedIntent, mComponentType, mMethodId);
    }
        return true;
    case R.id.track_intent: {
        if (!item.isChecked()) {
            XIntentsLab xIntentsLab = XIntentsLabStatic.getInstance();
            if (xIntentsLab.havePermission()) {
                createIntentTracker();
            } else {
                try {
                    startIntentSenderForResult(
                            xIntentsLab.getRequestPermissionIntent(getPackageName()).getIntentSender(),
                            REQUEST_CODE_REQUEST_INTENT_TRACKER_PERMISSION, null, 0, 0, 0);
                } catch (IntentSender.SendIntentException e) {
                    e.printStackTrace();
                    // TODO: can we handle this?
                }
            }
        } else {
            removeIntentTracker();
        }
        return true;
    }
    case R.id.disable_interception:
        getPackageManager().setComponentEnabledSetting(
                new ComponentName(this, IntentEditorInterceptedActivity.class),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
        Toast.makeText(this, R.string.interception_disabled, Toast.LENGTH_SHORT).show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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

/**
 * Clear the setting for default home.//  ww w.  j a  v a  2  s.  co  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.air.mobilebrowser.BrowserActivity.java

/**
 * Cleanup everything that was changed./* w w  w. j  a  v  a 2s  .  c  o m*/
 */
public void cleanup() {
    stopService(new Intent(getApplicationContext(), ActivityWatchService.class));
    //clear home and exit
    PackageManager pm = getPackageManager();
    ComponentName fauxHomeComponent = new ComponentName(getApplicationContext(), FauxHome.class);
    ComponentName homeComponent = new ComponentName(getApplicationContext(), BrowserActivity.class);

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

    mAudioManager.setMicrophoneMute(OrigSettings.getInstance().isMicMuted());

    String curKeyboard = KeyboardUtil.getKeyboardPackage(BrowserActivity.this.getContentResolver());

    if (!curKeyboard.equals(OrigSettings.getInstance().getKeyboard())) {

        KeyboardUtil.showInputChangedExitDialog(this, new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {

                finish();

            }
        });
    } else {
        finish();
    }
}

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 w w  w  .ja v a2 s.c om*/
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 {//  ww  w .  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:com.android.cts.verifier.managedprovisioning.ByodHelperActivity.java

private void startActivityInPrimary(Intent intent) {
    // Disable app components in the current profile, so only the counterpart in the other
    // profile can respond (via cross-profile intent filter)
    getPackageManager().setComponentEnabledSetting(new ComponentName(this, ByodFlowTestActivity.class),
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    startActivity(intent);// www.j  av  a2s.  co m
}

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);
    }/*w ww.j a  v a2s.  c o m*/
}

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);
    }/*from w w w . j  ava 2 s  .  co  m*/
}

From source file:com.chummy.jezebel.material.dark.activities.Main.java

public void setLauncherIconEnabled(boolean enabled) {
    int newState;
    PackageManager pm = getPackageManager();
    if (enabled) {
        newState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    } else {/*from w  w  w .  j a v  a  2s  . com*/
        newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }
    pm.setComponentEnabledSetting(
            new ComponentName(this, com.chummy.jezebel.material.dark.LauncherActivity.class), newState,
            PackageManager.DONT_KILL_APP);
}