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:co.edu.uniajc.vtf.content.SwipeContentActivity.java

@Override
protected void onResume() {
    ComponentName loComponent = new ComponentName(this, NetworkStatusReceiver.class);
    this.getPackageManager().setComponentEnabledSetting(loComponent,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    super.onResume();
}

From source file:com.tasomaniac.muzei.earthview.ui.SettingsFragment.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
    new BackupManager(getActivity()).dataChanged();

    // Potentially enable/disable the launcher activity if the settings button
    // preference has changed.
    final String launcherIntentKey = getString(R.string.pref_key_launcher_intent);
    if (isAdded() && launcherIntentKey.equals(s)) {

        final boolean hideLauncher = sharedPreferences.getBoolean(launcherIntentKey, false);
        getActivity().getPackageManager().setComponentEnabledSetting(
                new ComponentName(getActivity().getPackageName(), LAUNCHER_ACTIVITY_NAME),
                hideLauncher ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                        : PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }// ww w  . ja  va  2  s  . com
}

From source file:net.gsantner.opoc.util.ActivityUtils.java

public void setLauncherActivityEnabled(Class activityClass, boolean enable) {
    Context context = _context.getApplicationContext();
    PackageManager pkg = context.getPackageManager();
    ComponentName component = new ComponentName(context, activityClass);
    pkg.setComponentEnabledSetting(component, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}

From source file:com.p3authentication.preferences.Prefs.java

protected void showLauncherIcon() {
    // TODO Auto-generated method stub
    Prefs.this.getPackageManager().setComponentEnabledSetting(LAUNCHER_COMPONENT_NAME,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    ComponentName receiver = new ComponentName(Prefs.this, NumberListerner.class);
    PackageManager pm = Prefs.this.getPackageManager();

    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
    AccessPin.setEnabled(false);//from www. ja v a 2 s  .  c o m
}

From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java

@Override
public void onCreate() {
    super.onCreate();

    Log.i(TAG, "Start " + TorrentTaskService.class.getSimpleName());

    notifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    repo = new TorrentStorage(getApplicationContext());

    pref = new SettingsManager(getApplicationContext());
    pref.registerOnTrayPreferenceChangeListener(this);

    ComponentName powerReceiver = new ComponentName(getApplicationContext(), PowerReceiver.class);
    getPackageManager().setComponentEnabledSetting(powerReceiver,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

    if (pref.getBoolean(getString(R.string.pref_key_battery_control), false)
            && (Utils.getBatteryLevel(getApplicationContext()) <= Utils.getDefaultBatteryLowLevel())) {
        pauseTorrents.set(true);/*  ww  w. j  av a  2s. c o m*/
    }

    if (pref.getBoolean(getString(R.string.pref_key_download_and_upload_only_when_charging), false)
            && !Utils.isBatteryCharging(getApplicationContext())) {
        pauseTorrents.set(true);
    }

    if (pref.getBoolean(getString(R.string.pref_key_cpu_do_not_sleep), false)) {
        setKeepCpuAwake(true);
    }

    engineTask = new EngineTask(getApplicationContext(), this);
    exec.execute(engineTask);
}

From source file:am.roadpolice.roadpolice.alarm.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    if (context == null || intent == null) {
        Logger.error("AlarmReceiver", "onReceive(Context " + (context == null ? "null," : ",") + " Intent "
                + (intent == null ? "null)" : ")"));
        return;/*ww w.  j  ava 2s .  c  om*/
    }

    // Set Context
    mContext = context;

    // Get shared preferences.
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    // Check internet availability and only in that case start actions.
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    final boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    final String action = intent.getAction();
    // Catch Network change state.
    if (!TextUtils.isEmpty(action) && action.equals("android.net.conn.CONNECTIVITY_CHANGE")) {
        // If internet connection established
        if (isConnected) {
            // If didn't missed last update of data due to network issues do nothing,
            // otherwise proceed with data updating.
            final boolean missUpdateDueToNetworkIssue = sp
                    .getBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, false);
            if (!missUpdateDueToNetworkIssue)
                return;
        }
        // If user switch off Internet connection do not proceed.
        else
            return;
    }
    // Check Boot state.
    else if (!TextUtils.isEmpty(action) && action.equals("android.intent.action.BOOT_COMPLETED")) {
        // Get stored alarm time.
        final long nextAlarmTime = PreferenceUtils.getDataLong(context,
                PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, -1);
        if (nextAlarmTime != -1) {
            // Set new alarm, as after reboot alarm was switched off.
            if (mAlarmManager == null)
                mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

            Intent alarmIntent = new Intent(context, AlarmReceiver.class);
            if (mAlarmIntent == null)
                mAlarmIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);

            // Enable boot receiver
            ComponentName receiver = new ComponentName(context, AlarmReceiver.class);
            PackageManager pm = context.getPackageManager();
            pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                    PackageManager.DONT_KILL_APP);

            final int ui = DialogSettings.getUpdateInterval(context);
            AlarmType type = ui == DialogSettings.DAILY ? AlarmType.DAILY
                    : ui == DialogSettings.WEEKLY ? AlarmType.WEEKLY : AlarmType.MONTHLY;

            mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, nextAlarmTime, type.getValue(),
                    mAlarmIntent);
        }
        return;
    }
    // When alarm rise we appears in the block below.
    else {
        Logger.beep();
        Logger.beep();
        Logger.beep();
        // Calculating next alarm time.
        final Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        final int updateInterval = DialogSettings.getUpdateInterval(context);
        if (updateInterval == DialogSettings.DAILY)
            calendar.add(Calendar.DATE, 1);
        else if (updateInterval == DialogSettings.WEEKLY)
            calendar.add(Calendar.DATE, 7);
        else if (updateInterval == DialogSettings.MONTHLY)
            calendar.add(Calendar.MONTH, 1);
        else
            Logger.error("AlarmReceiver", "Unknown Update Interval.");

        // Next alarm time.
        final long nextAlarmTimeInMillis = calendar.getTimeInMillis();
        // Store next alarm time for further use.
        PreferenceUtils.storeDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, nextAlarmTimeInMillis);
    }

    if (!isConnected) {
        Logger.debug("AlarmReceiver", "No Internet connection, while receiving Alarm message");
        // If no internet connecting schedule data update, as soon
        // as internet connection will be available.
        SharedPreferences.Editor ed = sp.edit();
        ed.putBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, true);
        ed.apply();
        return;
    }

    final String cerNum = sp.getString(MainActivity.CER_NUMBER, MainActivity.EMPTY_STRING);
    final String regNum = sp.getString(MainActivity.REG_NUMBER, MainActivity.EMPTY_STRING);
    final boolean login = sp.getBoolean(MainActivity.AUTO_LOGIN, false);
    if (!login) { // If no auto login user detected.
        Logger.debug("AlarmReceiver", "Why we enter this case if no auto login users detected?");
        // Remove alarm.
        AlarmReceiver.createAlarm(context, AlarmReceiver.AlarmType.NONE);
        return;
    }

    if (TextUtils.isEmpty(cerNum) || TextUtils.isEmpty(regNum)) {
        Logger.debug("AlarmReceiver", "Why we enter this case if both data are null or empty?");
        // Remove alarm.
        AlarmReceiver.createAlarm(context, AlarmReceiver.AlarmType.NONE);
        // Remove auto login.
        SharedPreferences.Editor ed = sp.edit();
        ed.putBoolean(MainActivity.AUTO_LOGIN, false);
        ed.apply();
        return;
    }

    // Start downloading data from internet.
    Submitter submitter = new Submitter(cerNum, regNum, this);
    submitter.executeOnExecutor(Executors.newSingleThreadExecutor());
}

From source file:org.ametro.app.ApplicationEx.java

public void changeNetworkStateReceiverState(boolean enabled) {
    PackageManager manager = getPackageManager();
    ComponentName name = new ComponentName(this, NetworkStateReceiver.class);
    int state = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    manager.setComponentEnabledSetting(name, state, PackageManager.DONT_KILL_APP);
}

From source file:org.proninyaroslav.libretorrent.settings.BehaviorSettingsFragment.java

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());

    if (preference instanceof SwitchPreferenceCompat) {
        pref.put(preference.getKey(), (boolean) newValue);

        if (preference.getKey().equals(getString(R.string.pref_key_autostart))) {
            int flag = ((boolean) newValue ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
            ComponentName bootReceiver = new ComponentName(getActivity(), BootReceiver.class);

            getActivity().getPackageManager().setComponentEnabledSetting(bootReceiver, flag,
                    PackageManager.DONT_KILL_APP);
        }/* w  ww. j  ava2s . c  o m*/

    } else if (preference instanceof LightPreference) {
        LightPreference ledIndicatorColor = (LightPreference) findPreference(preference.getKey());
        ledIndicatorColor.forceSetValue((int) newValue);
        pref.put(preference.getKey(), (int) newValue);

    }

    return true;
}

From source file:com.p3authentication.preferences.Prefs.java

protected void hideLauncherIcon() {
    // TODO Auto-generated method stub

    AlertDialog.Builder builder = new AlertDialog.Builder(Prefs.this);
    builder.setTitle("Important!");
    builder.setMessage(/* w  w w . j  ava  2 s  .co  m*/
            "To launch P3 again, dial " + AccessPin.getText().toString() + " or set up your custom Pin below.");
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Prefs.this.getPackageManager().setComponentEnabledSetting(LAUNCHER_COMPONENT_NAME,
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

        }
    });
    builder.setIcon(android.R.drawable.ic_dialog_alert);
    builder.show();
    ComponentName receiver = new ComponentName(Prefs.this, NumberListerner.class);
    PackageManager pm = Prefs.this.getPackageManager();

    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
    AccessPin.setEnabled(true);

}

From source file:org.ametro.app.ApplicationEx.java

public void changeBootCompletedReceiverState(boolean enabled) {
    PackageManager manager = getPackageManager();
    ComponentName name = new ComponentName(this, BootCompletedReceiver.class);
    int state = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    manager.setComponentEnabledSetting(name, state, PackageManager.DONT_KILL_APP);
}