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:am.roadpolice.roadpolice.alarm.AlarmReceiver.java

/**
 * This function creates a new Alarm by given alarm type. if not {@link AlarmType#NONE}
 * value was given as a type alarm will be called Daily, Weekly or Monthly staring from
 * time when this function was called. All alarms which were created before will be canceled.
 *
 * @param context Application context//from   w  w  w .  j ava2s.c  o  m
 * @param type Alarm Type, accepted values are
 *              {@link AlarmType#NONE} if need to cancel all alarms,
 *              {@link AlarmType#DAILY} alarm will called daily
 *              {@link AlarmType#WEEKLY} alarm will called weekly
 *              {@link AlarmType#MONTHLY} alarm will called monthly
 */
public static void createAlarm(final Context context, AlarmType type) {

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());

    switch (type) {
    case DAILY:
        calendar.add(Calendar.DATE, 1);
        break;

    case WEEKLY:
        calendar.add(Calendar.DATE, 7);
        break;

    case MONTHLY:
        calendar.add(Calendar.MONTH, 1);
        break;
    }

    // Create Alarm Manager Object.
    if (mAlarmManager == null)
        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    //
    Intent intent = new Intent(context, AlarmReceiver.class);
    if (mAlarmIntent == null)
        mAlarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    // Remove all previously created alarms, before creating new one.
    if (mAlarmManager != null) {
        mAlarmManager.cancel(mAlarmIntent);

        // By default Disable Boot Receiver.
        int componentEnabledState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
        // For enabling/disabling Boot Receiver.
        ComponentName receiver = new ComponentName(context, AlarmReceiver.class);
        PackageManager pm = context.getPackageManager();

        // Set new alarm if provided interval is not none.
        if (!AlarmType.NONE.equals(type)) {
            Logger.debug("AlarmReceiver", String
                    .format("----> Next Update Date: %1$tA %1$tb %1$td %1$tY at %1$tI:%1$tM %1$Tp", calendar));
            // Enables Boot Receiver.
            componentEnabledState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
            // Set repeating alarm.
            final long timeInMillis = calendar.getTimeInMillis();
            mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeInMillis, type.getValue(),
                    mAlarmIntent);

            // Stores next Alert Time.
            PreferenceUtils.storeDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, timeInMillis);

        } else {
            PreferenceUtils.storeDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, -1);
        }

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

From source file:file_manager.Activity_files.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
    }//from  w  w  w .  jav a 2s .c o  m

    PackageManager pm = getPackageManager();
    boolean isInstalled = isPackageInstalled("de.baumann.pdfcreator", pm);

    if (isInstalled) {
        PackageManager p = getPackageManager();
        p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("de.baumann.pdfcreator");
        LaunchIntent.setAction("pdf_openFolder");
        startActivity(LaunchIntent);
        finish();
    }

    setContentView(R.layout.activity_file_manager);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit()
            .putString("files_startFolder",
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath())
            .apply();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    listView = (ListView) findViewById(R.id.listNotes);
    filter_layout = (RelativeLayout) findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    filter = (EditText) findViewById(R.id.myFilter);

    ImageButton ib_hideKeyboard = (ImageButton) findViewById(R.id.ib_hideKeyboard);
    ib_hideKeyboard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            filter_layout.setVisibility(View.GONE);
            setFilesList();
        }
    });

    //calling Notes_DbAdapter
    db = new DbAdapter_Files(this);
    db.open();

    setTitle();
    setFilesList();
}

From source file:com.doctoror.surprise.SurpriseActivity.java

@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
    mPackageManager.setComponentEnabledSetting(mReceiverComponent,
            isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);

    if (isChecked) {
        mAnimatorSurprise.setDisplayedChild(ANIMATOR_CHILD_PROGRESS);
        SurpriseService.executeSurprise(SurpriseActivity.this, true);
    }// www. jav  a2s .  c  o  m
}

From source file:org.ounl.lifelonglearninghub.nfcecology.scheduler.SampleAlarmReceiver.java

/**
 * Cancels the alarm.//  www.  ja  v  a 2  s  .c o  m
 * @param context
 */
public void cancelAlarm(Context context) {

    Log.i(CLASSNAME, "Alarm removed ");

    if (alarmMgr != null) {
        alarmMgr.cancel(alarmIntent);
    }

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

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

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

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.notification_layout, container, false);

    final Button button = (Button) rootView.findViewById(R.id.Button);
    final Button button2 = (Button) rootView.findViewById(R.id.Button2);
    final Button button3 = (Button) rootView.findViewById(R.id.Button3);

    button.setOnClickListener(new View.OnClickListener() {
        @Override//from   www  . j av a 2s . c om
        public void onClick(View v) {
            showTimePickerDialog(v);
            AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f);
            animation1.setDuration(500);
            button.startAnimation(animation1);

        }
    });

    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDatePickerDialog(v);
            AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f);
            animation1.setDuration(500);
            button2.startAnimation(animation1);
        }
    });

    button3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setNotification();
            AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f);
            animation1.setDuration(500);
            button3.startAnimation(animation1);
        }
    });

    button3.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            ComponentName receiver = new ComponentName(getActivity(), AlertClass.class);
            PackageManager pm = getActivity().getPackageManager();
            pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);

            Intent intent = new Intent(getActivity(), AlertClass.class);
            AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
            alarmManager.cancel(PendingIntent.getBroadcast(getActivity().getApplicationContext(), 1, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT));
            Toast.makeText(getActivity(), "Notification reset!", Toast.LENGTH_SHORT).show();

            AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f);
            animation1.setDuration(500);
            button3.startAnimation(animation1);

            //It would not let me assign void so I
            return true;
        }
    });

    return rootView;
}

From source file:com.grarak.kerneladiutor.utils.Utils.java

public static void setStartActivity(boolean material, Context context) {
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(new ComponentName(context, StartActivity.class),
            material ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
    pm.setComponentEnabledSetting(//from w  w w  . jav  a2s.  c  o m
            new ComponentName(BuildConfig.APPLICATION_ID,
                    BuildConfig.APPLICATION_ID + ".activities.StartActivity-Material"),
            material ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.afwsamples.testdpc.provision.PostProvisioningTask.java

public boolean performPostProvisioningOperations(Intent intent) {
    if (isPostProvisioningDone()) {
        return false;
    }//from w  w  w .j a  v  a2 s.  c  o  m
    markPostProvisioningDone();

    // From M onwards, permissions are not auto-granted, so we need to manually grant
    // permissions for TestDPC.
    if (Util.isAtLeastM()) {
        autoGrantRequestedPermissionsToSelf();
    }

    // Retreive the admin extras bundle, which we can use to determine the original context for
    // TestDPCs launch.
    PersistableBundle extras = intent.getParcelableExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE);
    if (BuildCompat.isAtLeastO()) {
        maybeSetAffiliationIds(extras);
    }

    // Hide the setup launcher when this app is the admin
    mContext.getPackageManager().setComponentEnabledSetting(
            new ComponentName(mContext, SETUP_MANAGEMENT_LAUNCH_ACTIVITY),
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

    return true;
}

From source file:eu.istvank.apps.lenslog.receivers.NotifyAlarmReceiver.java

/**
 * Cancels the alarm.//ww w. ja v a 2 s.  co m
 * @param context
 */
public void cancelAlarm(Context context) {
    // If the alarm has been set, cancel it.
    if (alarmMgr != null) {
        alarmMgr.cancel(alarmIntent);
    }

    // Disable {@code SampleBootReceiver} so that it doesn't automatically restart the
    // alarm when the device is rebooted.
    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();

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

From source file:de.j4velin.wifiAutoOff.Preferences.java

@SuppressLint("NewApi")
@Override/* w ww.  j a  v a  2s  .  c om*/
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        CompoundButton enable = (CompoundButton) menu.findItem(R.id.enable).getActionView();
        if (android.os.Build.VERSION.SDK_INT < 14) {
            enable.setText("Enable");
        }
        enable.setChecked(getPackageManager().getComponentEnabledSetting(
                new ComponentName(this, Receiver.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
        // disable initially if not checked
        if (!enable.isChecked()) {
            @SuppressWarnings("deprecation")
            PreferenceScreen ps = getPreferenceScreen();
            for (int i = 0; i < ps.getPreferenceCount(); i++) {
                ps.getPreference(i).setEnabled(false);
            }
        }
        enable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                @SuppressWarnings("deprecation")
                PreferenceScreen ps = getPreferenceScreen();
                // start at 1 to skip "status" preference
                for (int i = 1; i < ps.getPreferenceCount(); i++) {
                    ps.getPreference(i).setEnabled(isChecked);
                }
                getPackageManager().setComponentEnabledSetting(
                        new ComponentName(Preferences.this, Receiver.class),
                        isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
                if (!isChecked)
                    stopService(new Intent(Preferences.this, ScreenChangeDetector.class));
                getPackageManager().setComponentEnabledSetting(
                        new ComponentName(Preferences.this, ScreenChangeDetector.class),
                        isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
        });
    }
    return true;
}

From source file:com.farmerbb.taskbar.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LocalBroadcastManager.getInstance(this).registerReceiver(switchReceiver,
            new IntentFilter("com.farmerbb.taskbar.UPDATE_SWITCH"));

    final SharedPreferences pref = U.getSharedPreferences(this);
    SharedPreferences.Editor editor = pref.edit();

    switch (pref.getString("theme", "light")) {
    case "light":
        setTheme(R.style.AppTheme);//from w  w w .ja  va  2 s  .c  o  m
        break;
    case "dark":
        setTheme(R.style.AppTheme_Dark);
        break;
    }

    if (pref.getBoolean("taskbar_active", false) && !U.isServiceRunning(this, NotificationService.class))
        editor.putBoolean("taskbar_active", false);

    // Ensure that components that should be enabled are enabled properly
    boolean launcherEnabled = (pref.getBoolean("launcher", false) && U.canDrawOverlays(this))
            || U.hasSupportLibrary(this);
    editor.putBoolean("launcher", launcherEnabled);

    editor.apply();

    ComponentName component = new ComponentName(this, HomeActivity.class);
    getPackageManager().setComponentEnabledSetting(component,
            launcherEnabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);

    ComponentName component2 = new ComponentName(this, KeyboardShortcutActivity.class);
    getPackageManager().setComponentEnabledSetting(component2,
            pref.getBoolean("keyboard_shortcut", false) ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);

    ComponentName component3 = new ComponentName(this, ShortcutActivity.class);
    getPackageManager().setComponentEnabledSetting(component3,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);

    ComponentName component4 = new ComponentName(this, StartTaskbarActivity.class);
    getPackageManager().setComponentEnabledSetting(component4, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

    if (!launcherEnabled)
        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(new Intent("com.farmerbb.taskbar.KILL_HOME_ACTIVITY"));

    if (BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID))
        proceedWithAppLaunch(savedInstanceState);
    else {
        File file = new File(getFilesDir() + File.separator + "imported_successfully");
        if (freeVersionInstalled() && !file.exists()) {
            startActivity(new Intent(this, ImportSettingsActivity.class));
            finish();
        } else {
            proceedWithAppLaunch(savedInstanceState);
        }
    }
}