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.ar.ARViewActivity.java

@Override
protected void onResume() {
    super.onResume();
    ComponentName loComponent = new ComponentName(this, NetworkStatusReceiver.class);
    this.getPackageManager().setComponentEnabledSetting(loComponent,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    this.loadPosition();
    if (this.architectView != null) {
        this.architectView.onResume();
    }/* ww w  .j  a  v  a2s  .c o  m*/
}

From source file:com.appsaur.tarucassist.AlarmReceiver.java

public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Put Reminder ID in Intent Extra
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
    mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // Calculate notification timein
    Calendar c = Calendar.getInstance();
    long currentTime = c.getTimeInMillis();
    long diffTime = calendar.getTimeInMillis() - currentTime;

    // Start alarm using initial notification time and repeat interval time
    mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime,
            RepeatTime, mPendingIntent);

    // Restart alarm if device is rebooted
    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.github.michalbednarski.intentslab.StartActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_settings:
        startActivity(new Intent(this, PrefsActivity.class));
        return true;
    case R.id.interception: {
        final PackageManager packageManager = getPackageManager();
        boolean enable = packageManager.getComponentEnabledSetting(
                mInterceptActivityComponentName) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED;

        packageManager//  ww w . ja  v  a  2  s.co  m
                .setComponentEnabledSetting(mInterceptActivityComponentName,
                        enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);

        Toast.makeText(this,
                enable ? getString(R.string.interception_enabled) : getString(R.string.interception_disabled),
                Toast.LENGTH_SHORT).show();
        ActivityCompat.invalidateOptionsMenu(this);
        return true;
    }
    case R.id.system_services:
        (new SystemServicesDialog()).show(getSupportFragmentManager(), "systemServices");
        return true;
    case R.id.provider_lab:
        startActivity(new Intent(StartActivity.this, AdvancedQueryActivity.class));
        return true;
    }
    return false;
}

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

public void setNotification() {

    NotificationItemClass notificationItemClass = new NotificationItemClass();
    DataBaseHelper db = new DataBaseHelper(getActivity());

    db.getWritableDatabase();/*from w ww .j a  v  a  2s  .c o m*/
    db.addNotification(notificationItemClass);
    db.upDateDataBaseNotification(notificationItemClass);
    db.getNotification(notificationItemClass);

    if (db.notification <= 0) {
        Toast.makeText(getActivity(), "Please set a time for the notification", Toast.LENGTH_SHORT).show();
    }

    else {

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

        Intent intent = new Intent(getActivity(), AlertClass.class);
        AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, db.notification, PendingIntent.getBroadcast(
                getActivity().getApplicationContext(), 1, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        Toast.makeText(getActivity(), "Notification issued", Toast.LENGTH_SHORT).show();
        Log.d("Trekkinly", "AlarmNotification Called");

    }
}

From source file:com.soft.pushsender.DemoActivity.java

private void enPush() {
    //Enable push notifications
    ComponentName receiver = new ComponentName(context, GcmBroadcastReceiver.class);

    PackageManager pm = context.getPackageManager();

    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.android.usbtuner.UsbInputController.java

/**
 * Enable/disable the component {@link UsbTunerTvInputService}.
 *
 * @param context {@link Context} instance
 * @param enabled {@code true} to enable the service; otherwise {@code false}
 *//*from www.ja v  a2  s.c  o m*/
private void enableUsbTunerTvInputService(Context context, boolean enabled) {
    PackageManager pm = context.getPackageManager();
    ComponentName USBTUNER = new ComponentName(context, UsbTunerTvInputService.class);

    // Don't kill app by enabling/disabling TvActivity. If LC is killed by enabling/disabling
    // TvActivity, the following pm.setComponentEnabledSetting doesn't work.
    ((TvApplication) context.getApplicationContext()).handleInputCountChanged(true, enabled, true);
    // Since PackageManager.DONT_KILL_APP delays the operation by 10 seconds
    // (PackageManagerService.BROADCAST_DELAY), we'd better avoid using it. It is used only
    // when the LiveChannels app is active since we don't want to kill the running app.
    int flags = TvApplication.getSingletons(context).getMainActivityWrapper().isCreated()
            ? PackageManager.DONT_KILL_APP
            : 0;
    int newState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (newState != pm.getComponentEnabledSetting(USBTUNER)) {
        // Send/cancel the USB tuner TV input setup recommendation card.
        TunerSetupActivity.onTvInputEnabled(context, enabled);
        // Enable/disable the USB tuner TV input.
        pm.setComponentEnabledSetting(USBTUNER, newState, flags);
        if (DEBUG)
            Log.d(TAG, "Status updated:" + enabled);
    }
    if (enabled && BuildCompat.isAtLeastN()) {
        TvInputInfo info = mDvbDeviceAccessor.buildTvInputInfo(context);
        if (info != null) {
            Log.i(TAG, "TvInputInfo updated: " + info.toString());
            ((TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE)).updateTvInputInfo(info);
        }
    }
}

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

@SuppressWarnings("deprecation")
@Override//  w  w w.j  av  a2s .c  o  m
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    addPreferencesFromResource(R.xml.pref);

    AccessPin = (EditTextPreference) getPreferenceManager().findPreference("KeypadKey");
    final Preference ResetPreference = getPreferenceManager().findPreference("reset_data");
    final Preference EULAPreference = getPreferenceManager().findPreference("eula");
    final Preference AboutUsPreference = getPreferenceManager().findPreference("about_us");
    final Preference UnlockAppsPreference = getPreferenceManager().findPreference("unlock_apps");
    final Preference TouchTolerance = getPreferenceManager().findPreference("touch_tolerance");
    final Preference RedownloadImage = getPreferenceManager().findPreference("redownload_images");
    final Preference RateApp = getPreferenceManager().findPreference("rate_app");
    final CheckBoxPreference GhostStatusPref = (CheckBoxPreference) getPreferenceManager()
            .findPreference("GhostStatus");
    final CheckBoxPreference StartServicePref = (CheckBoxPreference) getPreferenceManager()
            .findPreference("startup_service");
    final ListPreference patterntype = (ListPreference) getPreferenceManager().findPreference("PatternType");
    final ListPreference PatternStealth = (ListPreference) getPreferenceManager()
            .findPreference("PatternStealth");
    if (patterntype.getValue().toString().equals("No Pattern")) {
        PatternStealth.setEnabled(false);
    } else {
        PatternStealth.setEnabled(true);
    }

    if (GhostStatusPref.isChecked()) {
        AccessPin.setEnabled(true);
    } else {
        AccessPin.setEnabled(false);
    }
    AccessPin.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // TODO Auto-generated method stub
            if (newValue.toString().trim().equals("")) {

                Toast.makeText(Prefs.this, "Your Custom PIN cannot be empty.", Toast.LENGTH_LONG).show();

                return false;
            } else if (newValue.toString().length() < 5) {
                Toast.makeText(Prefs.this, "Your Custom PIN must be atleast 5 Digits.", Toast.LENGTH_LONG)
                        .show();

                return false;
            }
            Toast.makeText(Prefs.this, "Your Custom PIN is set.", Toast.LENGTH_LONG).show();
            return true;
        }

    });
    GhostStatusPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.toString().equals("true")) {
                hideLauncherIcon();
                Toast.makeText(Prefs.this, "P3 hidden from App Menu", Toast.LENGTH_SHORT).show();
            } else {
                showLauncherIcon();
                Toast.makeText(Prefs.this, "P3 visible on App Menu", Toast.LENGTH_SHORT).show();
            }
            return true;
        }

    });
    StartServicePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.toString().equals("true")) {
                ComponentName receiver = new ComponentName(Prefs.this, Startup.class);
                PackageManager pm = getPackageManager();

                pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                        PackageManager.DONT_KILL_APP);

            } else {
                ComponentName receiver = new ComponentName(Prefs.this, Startup.class);
                PackageManager pm = getPackageManager();

                pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
            return true;
        }

    });
    patterntype.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // TODO Auto-generated method stub
            if (!newValue.toString().equals("No Pattern")) {
                PatternStealth.setEnabled(true);
            } else {
                PatternStealth.setEnabled(false);
            }
            return true;
        }
    });
    ResetPreference.setOnPreferenceClickListener(this);
    UnlockAppsPreference.setOnPreferenceClickListener(this);
    TouchTolerance.setOnPreferenceClickListener(this);
    RedownloadImage.setOnPreferenceClickListener(this);
    RateApp.setOnPreferenceClickListener(this);
    AboutUsPreference.setOnPreferenceClickListener(this);
    EULAPreference.setOnPreferenceClickListener(this);

}

From source file:com.heightechllc.breakify.MainActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();

    // Enable or disable the RescheduleReceiver, which restores AlarmManagers when the system
    //  boots or the time changes. We only want it enabled if an alarm is scheduled, or if
    //  Scheduled Start is enabled.
    int enabledState;
    if (timerState == TIMER_STATE_RUNNING || ScheduledStart.isEnabled(this))
        enabledState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    else/*  www. j a  v a  2 s .  co  m*/
        enabledState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;

    ComponentName receiver = new ComponentName(this, RescheduleReceiver.class);
    getPackageManager().setComponentEnabledSetting(receiver, enabledState, PackageManager.DONT_KILL_APP);

    // Send any unsent analytics events
    if (mixpanel != null)
        mixpanel.flush();
}

From source file:de.stadtrallye.rallyesoft.services.UploadService.java

private void setEnableNetworkStateListener(boolean enable) {
    ComponentName receiver = new ComponentName(getApplicationContext(), NetworkStatusReceiver.class);

    PackageManager pm = getApplicationContext().getPackageManager();

    pm.setComponentEnabledSetting(receiver, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}

From source file:com.svpino.longhorn.MarketCollectorService.java

@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = getSharedPreferences(Constants.PREFERENCES, Context.MODE_PRIVATE);
    long lastUpdate = sharedPreferences.getLong(Constants.PREFERENCE_COLLECTOR_LAST_UPDATE, 0);
    boolean retrying = sharedPreferences.getBoolean(Constants.PREFERENCE_COLLECTOR_RETRYING, false);
    int retries = sharedPreferences.getInt(Constants.PREFERENCE_COLLECTOR_RETRIES, 0);
    boolean wereWeWaitingForConnectivity = sharedPreferences
            .getBoolean(Constants.PREFERENCE_STATUS_WAITING_FOR_CONNECTIVITY, false);

    boolean isGlobalCollection = intent.getExtras() == null
            || (intent.getExtras() != null && !intent.getExtras().containsKey(EXTRA_TICKER));

    if (wereWeWaitingForConnectivity) {
        Editor editor = sharedPreferences.edit();
        editor.putBoolean(Constants.PREFERENCE_STATUS_WAITING_FOR_CONNECTIVITY, false);
        editor.commit();//from  w  ww .j  a  va  2  s  . c o m
    }

    if (retrying && isGlobalCollection) {
        Editor editor = sharedPreferences.edit();
        editor.putBoolean(Constants.PREFERENCE_COLLECTOR_RETRYING, false);
        editor.putInt(Constants.PREFERENCE_COLLECTOR_RETRIES, 0);
        editor.commit();

        ((AlarmManager) getSystemService(Context.ALARM_SERVICE))
                .cancel(Extensions.createPendingIntent(this, Constants.SCHEDULE_RETRY));
    }

    long currentTime = System.currentTimeMillis();
    if (retrying || wereWeWaitingForConnectivity || !isGlobalCollection
            || (isGlobalCollection && currentTime - lastUpdate > Constants.COLLECTOR_MIN_REFRESH_INTERVAL)) {
        String[] tickers = null;

        if (isGlobalCollection) {
            Log.d(LOG_TAG, "Executing global market information collection...");
            tickers = DataProvider.getStockDataTickers(this);
        } else {
            String ticker = intent.getExtras().containsKey(EXTRA_TICKER)
                    ? intent.getExtras().getString(EXTRA_TICKER)
                    : null;

            Log.d(LOG_TAG, "Executing market information collection for ticker " + ticker + ".");

            tickers = new String[] { ticker };
        }

        try {
            collect(tickers);

            if (isGlobalCollection) {
                Editor editor = sharedPreferences.edit();
                editor.putLong(Constants.PREFERENCE_COLLECTOR_LAST_UPDATE, System.currentTimeMillis());
                editor.commit();
            }

            DataProvider.notifyDataCollectionIsFinished(this, tickers);

            Log.d(LOG_TAG, "Market information collection was successfully completed");
        } catch (Exception e) {
            Log.e(LOG_TAG, "Market information collection failed.", e);

            if (Extensions.areWeOnline(this)) {
                Log.d(LOG_TAG, "Scheduling an alarm for retrying a global market information collection...");

                retries++;

                Editor editor = sharedPreferences.edit();
                editor.putBoolean(Constants.PREFERENCE_COLLECTOR_RETRYING, true);
                editor.putInt(Constants.PREFERENCE_COLLECTOR_RETRIES, retries);
                editor.commit();

                long interval = Constants.COLLECTOR_MIN_RETRY_INTERVAL * retries;
                if (interval > Constants.COLLECTOR_MAX_REFRESH_INTERVAL) {
                    interval = Constants.COLLECTOR_MAX_REFRESH_INTERVAL;
                }

                ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).set(AlarmManager.RTC,
                        System.currentTimeMillis() + interval,
                        Extensions.createPendingIntent(this, Constants.SCHEDULE_RETRY));
            } else {
                Log.d(LOG_TAG,
                        "It appears that we are not online, so let's start listening for connectivity updates.");

                Editor editor = sharedPreferences.edit();
                editor.putBoolean(Constants.PREFERENCE_STATUS_WAITING_FOR_CONNECTIVITY, true);
                editor.commit();

                ComponentName componentName = new ComponentName(this, ConnectivityBroadcastReceiver.class);
                getPackageManager().setComponentEnabledSetting(componentName,
                        PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            }
        }
    } else if (isGlobalCollection && currentTime - lastUpdate <= Constants.COLLECTOR_MIN_REFRESH_INTERVAL) {
        Log.d(LOG_TAG, "Global market information collection will be skipped since it was performed less than "
                + (Constants.COLLECTOR_MIN_REFRESH_INTERVAL / 60 / 1000) + " minutes ago.");
    }

    stopSelf();
}