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:org.proninyaroslav.libretorrent.settings.SettingsManager.java

public static void initPreferences(Context context) {
    SettingsManager pref = new SettingsManager(context);

    String keyAutostart = context.getString(R.string.pref_key_autostart);
    int flag = (pref.getBoolean(keyAutostart, false) ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
    ComponentName bootReceiver = new ComponentName(context, BootReceiver.class);
    context.getPackageManager().setComponentEnabledSetting(bootReceiver, flag, PackageManager.DONT_KILL_APP);

    String keySaveTorrentIn = context.getString(R.string.pref_key_save_torrents_in);
    if (pref.getString(keySaveTorrentIn, null) == null) {
        pref.put(keySaveTorrentIn, FileIOUtils.getDefaultDownloadPath());
    }//w  w w. j  a v  a2 s.com

    String keyFileManagerLastDir = context.getString(R.string.pref_key_filemanager_last_dir);
    if (pref.getString(keyFileManagerLastDir, null) == null) {
        pref.put(keyFileManagerLastDir, FileIOUtils.getDefaultDownloadPath());
    }

    String keyMoveAfterDownloadIn = context.getString(R.string.pref_key_move_after_download_in);
    if (pref.getString(keyMoveAfterDownloadIn, null) == null) {
        pref.put(keyMoveAfterDownloadIn, FileIOUtils.getDefaultDownloadPath());
    }

    String keyMaxDownloadSpeedLimit = context.getString(R.string.pref_key_max_download_speed);
    if (pref.getInt(keyMaxDownloadSpeedLimit, -1) == -1) {
        pref.put(keyMaxDownloadSpeedLimit, 0);
    }

    String keyMaxUploadSpeedLimit = context.getString(R.string.pref_key_max_upload_speed);
    if (pref.getInt(keyMaxUploadSpeedLimit, -1) == -1) {
        pref.put(keyMaxUploadSpeedLimit, 0);
    }

    String keyMaxConnections = context.getString(R.string.pref_key_max_connections);
    if (pref.getInt(keyMaxConnections, -1) == -1) {
        pref.put(keyMaxConnections, TorrentEngine.DEFAULT_CONNECTIONS_LIMIT);
    }

    String keyMaxActiveUploads = context.getString(R.string.pref_key_max_active_uploads);
    if (pref.getInt(keyMaxActiveUploads, -1) == -1) {
        pref.put(keyMaxActiveUploads, TorrentEngine.DEFAULT_ACTIVE_SEEDS);
    }

    String keyMaxActiveDownloads = context.getString(R.string.pref_key_max_active_downloads);
    if (pref.getInt(keyMaxActiveDownloads, -1) == -1) {
        pref.put(keyMaxActiveDownloads, TorrentEngine.DEFAULT_ACTIVE_DOWNLOADS);
    }

    String keyMaxActiveTorrents = context.getString(R.string.pref_key_max_active_torrents);
    if (pref.getInt(keyMaxActiveTorrents, -1) == -1) {
        pref.put(keyMaxActiveTorrents, TorrentEngine.DEFAULT_ACTIVE_LIMIT);
    }

    String keyNotifySound = context.getString(R.string.pref_key_notify_sound);
    if (pref.getString(keyMaxActiveTorrents, null) == null) {
        pref.put(keyNotifySound, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString());
    }

    String keyLedIndicatorColor = context.getString(R.string.pref_key_led_indicator_color_notify);
    if (pref.getInt(keyLedIndicatorColor, -1) == -1) {
        pref.put(keyLedIndicatorColor, ContextCompat.getColor(context, R.color.primary));
    }

    String keyProxyType = context.getString(R.string.pref_key_proxy_type);
    if (pref.getInt(keyProxyType, -1) == -1) {
        pref.put(keyProxyType, Integer.parseInt(context.getString(R.string.pref_proxy_type_none_value)));
    }

    String keyProxyPort = context.getString(R.string.pref_key_proxy_port);
    if (pref.getInt(keyProxyPort, -1) == -1) {
        pref.put(keyProxyPort, TorrentEngine.DEFAULT_PROXY_PORT);
    }

    String keyEncryptMode = context.getString(R.string.pref_key_enc_mode);
    if (pref.getInt(keyEncryptMode, -1) == -1) {
        pref.put(keyEncryptMode, Integer.parseInt(context.getString(R.string.pref_enc_mode_prefer_value)));
    }
}

From source file:damo.three.ie.prepay.ConnectivityReceiver.java

/**
 * Disables ConnectivityReceiver//  w  w  w .  j  a v  a  2 s. c o  m
 */
private static void disableReceiver(Context context) {
    ComponentName component = new ComponentName(context, ConnectivityReceiver.class);
    context.getPackageManager().setComponentEnabledSetting(component,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}

From source file:com.farmerbb.taskbar.receiver.DisableHomeReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences pref = U.getSharedPreferences(context);
    pref.edit().putBoolean("launcher", false).apply();

    ComponentName component = new ComponentName(context, HomeActivity.class);
    context.getPackageManager().setComponentEnabledSetting(component,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

    LocalBroadcastManager.getInstance(context)
            .sendBroadcast(new Intent("com.farmerbb.taskbar.KILL_HOME_ACTIVITY"));
}

From source file:townley.stuart.app.android.trekkinly.AlertClass.java

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

    NotificationItemClass notificationItemClass = new NotificationItemClass();
    DataBaseHelper db = new DataBaseHelper(context);
    db.getWritableDatabase();// w  w w. j av a 2 s .  com
    db.getNotification(notificationItemClass);

    if (db.notification <= System.currentTimeMillis()) {
        createNotification(context, "Something is missing!", "Click here for more details!", "Alert");

        ComponentName receiver = new ComponentName(context, AlertClass.class);
        PackageManager pm = context.getPackageManager();
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);

        intent = new Intent(context, AlertClass.class);
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.cancel(PendingIntent.getBroadcast(context.getApplicationContext(), 1, intent,
                PendingIntent.FLAG_UPDATE_CURRENT));
    }

    else if (db.notification > System.currentTimeMillis()) {
        intent = new Intent(context, AlertClass.class);
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, db.notification, PendingIntent
                .getBroadcast(context.getApplicationContext(), 1, intent, PendingIntent.FLAG_UPDATE_CURRENT));
    }
}

From source file:uk.co.ashtonbrsc.intentexplode.Settings.java

public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (preference == interceptEnabledPreference) {

        Boolean enabled = (Boolean) newValue;
        int flag = (enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
        ComponentName component = new ComponentName(Settings.this, Explode.class);

        getPackageManager().setComponentEnabledSetting(component, flag, PackageManager.DONT_KILL_APP);
    }// ww w  . ja v  a2s  .  com
    return true;
}

From source file:net.eledge.android.europeana.service.receiver.BlogCheckerReceiver.java

public void disableBlogChecker(Context context) {
    if (alarmManager != null) {
        alarmManager.cancel(blogCheckerIntent);
    }//from ww  w.  ja v  a2s.c  o  m

    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();

    if (pm != null) {
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }
}

From source file:me.myatminsoe.myansms.SMSdroid.java

@Override
public void onCreate() {
    try {/*from w  ww . j  a v a  2  s. c o m*/
        Class.forName("android.os.AsyncTask");
    } catch (Throwable ignore) {
    }

    super.onCreate();
    Log.i(TAG, "init SMSdroid v" + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")");

    // check for default app only when READ_SMS was granted
    // this may need a second launch on Android 6.0 though
    if (hasPermission(this, Manifest.permission.READ_SMS)) {
        final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
        int state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
        if (p.getBoolean(PreferencesActivity.PREFS_ACTIVATE_SENDER, true)) {
            try {
                Cursor c = getContentResolver().query(SenderActivity.URI_SENT, PROJECTION, null, null,
                        "_id LIMIT 1");
                if (c == null) {
                    Log.i(TAG, "disable .Sender: cursor=null");
                } else if (SmsManager.getDefault() == null) {
                    Log.i(TAG, "disable .Sender: SmsManager=null");
                } else {
                    state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
                    Log.d(TAG, "enable .Sender");
                }
                if (c != null && !c.isClosed()) {
                    c.close();
                }
            } catch (IllegalArgumentException | SQLiteException e) {

            }
        } else {
            Log.i(TAG, "disable .Sender");
        }
        getPackageManager().setComponentEnabledSetting(new ComponentName(this, SenderActivity.class), state,
                PackageManager.DONT_KILL_APP);
    } else {
        Log.w(TAG, "ignore .Sender state, READ_SMS permission is missing to check default app");
    }
}

From source file:de.ub0r.android.smsdroid.SMSdroid.java

@Override
public void onCreate() {
    try {//  w w  w . jav a2 s . co  m
        Class.forName("android.os.AsyncTask");
    } catch (Throwable ignore) {
    }

    super.onCreate();
    Log.i(TAG, "init SMSdroid v" + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")");

    // check for default app only when READ_SMS was granted
    // this may need a second launch on Android 6.0 though
    if (hasPermission(this, Manifest.permission.READ_SMS)) {
        final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
        int state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
        if (p.getBoolean(PreferencesActivity.PREFS_ACTIVATE_SENDER, true)) {
            try {
                Cursor c = getContentResolver().query(SenderActivity.URI_SENT, PROJECTION, null, null,
                        "_id LIMIT 1");
                if (c == null) {
                    Log.i(TAG, "disable .Sender: cursor=null");
                } else if (SmsManager.getDefault() == null) {
                    Log.i(TAG, "disable .Sender: SmsManager=null");
                } else {
                    state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
                    Log.d(TAG, "enable .Sender");
                }
                if (c != null && !c.isClosed()) {
                    c.close();
                }
            } catch (IllegalArgumentException | SQLiteException e) {
                Log.e(TAG, "disable .Sender: ", e.getMessage(), e);
            }
        } else {
            Log.i(TAG, "disable .Sender");
        }
        getPackageManager().setComponentEnabledSetting(new ComponentName(this, SenderActivity.class), state,
                PackageManager.DONT_KILL_APP);
    } else {
        Log.w(TAG, "ignore .Sender state, READ_SMS permission is missing to check default app");
    }
}

From source file:com.tonikorin.cordova.plugin.autostart.AutoStart.java

private void setAutoStart(boolean enabled) {

    Context context = cordova.getActivity().getApplicationContext();
    int componentState;
    SharedPreferences sp = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    if (enabled) {
        componentState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
        // Store the class name of your main activity for AppStarter
        editor.putString(CLASS_NAME, cordova.getActivity().getLocalClassName());
    } else {/*from w  ww  .j  a  v a2 s.  c  o m*/
        componentState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
        editor.remove(CLASS_NAME);
    }
    editor.commit();
    // Enable or Disable BootCompletedReceiver
    ComponentName bootCompletedReceiver = new ComponentName(context, BootCompletedReceiver.class);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(bootCompletedReceiver, componentState, PackageManager.DONT_KILL_APP);
}

From source file:com.example.android.powerreceiver.MainActivity.java

@Override
protected void onStop() {
    //Disable the broadcast receiver when the app is visible
    mPackageManager.setComponentEnabledSetting(mReceiverComponentName,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    super.onStop();
}