List of usage examples for android.content.pm PackageManager DONT_KILL_APP
int DONT_KILL_APP
To view the source code for android.content.pm PackageManager DONT_KILL_APP.
Click Source Link
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/* ww w.j a v a2 s.com*/ 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(//ww w.java 2 s . co 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 va 2 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./*from w w w. j a v a 2 s . c o 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:com.android.messaging.receiver.SmsReceiver.java
/** * Enable or disable the SmsReceiver as appropriate. Pre-KLP we use this receiver for * receiving incoming SMS messages. For KLP+ this receiver is not used when running as the * primary user and the SmsDeliverReceiver is used for receiving incoming SMS messages. * When running as a secondary user, this receiver is still used to trigger the incoming * notification.// w ww .j av a 2s .c o m */ public static void updateSmsReceiveHandler(final Context context) { boolean smsReceiverEnabled; boolean mmsWapPushReceiverEnabled; boolean respondViaMessageEnabled; boolean broadcastAbortEnabled; if (OsUtil.isAtLeastKLP()) { // When we're running as the secondary user, we don't get the new SMS_DELIVER intent, // only the primary user receives that. As secondary, we need to go old-school and // listen for the SMS_RECEIVED intent. For the secondary user, use this SmsReceiver // for both sms and mms notification. For the primary user on KLP (and above), we don't // use the SmsReceiver. smsReceiverEnabled = OsUtil.isSecondaryUser(); // On KLP use the new deliver event for mms mmsWapPushReceiverEnabled = false; // On KLP we need to always enable this handler to show in the list of sms apps respondViaMessageEnabled = true; // On KLP we don't need to abort the broadcast broadcastAbortEnabled = false; } else { // On JB we use the sms receiver for both sms/mms delivery final boolean carrierSmsEnabled = PhoneUtils.getDefault().isSmsEnabled(); smsReceiverEnabled = carrierSmsEnabled; // On JB we use the mms receiver when sms/mms is enabled mmsWapPushReceiverEnabled = carrierSmsEnabled; // On JB this is dynamic to make sure we don't show in dialer if sms is disabled respondViaMessageEnabled = carrierSmsEnabled; // On JB we need to abort broadcasts if SMS is enabled broadcastAbortEnabled = carrierSmsEnabled; } final PackageManager packageManager = context.getPackageManager(); final boolean logv = LogUtil.isLoggable(TAG, LogUtil.VERBOSE); if (smsReceiverEnabled) { if (logv) { LogUtil.v(TAG, "Enabling SMS message receiving"); } packageManager.setComponentEnabledSetting(new ComponentName(context, SmsReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { if (logv) { LogUtil.v(TAG, "Disabling SMS message receiving"); } packageManager.setComponentEnabledSetting(new ComponentName(context, SmsReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } if (mmsWapPushReceiverEnabled) { if (logv) { LogUtil.v(TAG, "Enabling MMS message receiving"); } packageManager.setComponentEnabledSetting(new ComponentName(context, MmsWapPushReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { if (logv) { LogUtil.v(TAG, "Disabling MMS message receiving"); } packageManager.setComponentEnabledSetting(new ComponentName(context, MmsWapPushReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } if (broadcastAbortEnabled) { if (logv) { LogUtil.v(TAG, "Enabling SMS/MMS broadcast abort"); } packageManager.setComponentEnabledSetting(new ComponentName(context, AbortSmsReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); packageManager.setComponentEnabledSetting(new ComponentName(context, AbortMmsWapPushReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { if (logv) { LogUtil.v(TAG, "Disabling SMS/MMS broadcast abort"); } packageManager.setComponentEnabledSetting(new ComponentName(context, AbortSmsReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); packageManager.setComponentEnabledSetting(new ComponentName(context, AbortMmsWapPushReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } if (respondViaMessageEnabled) { if (logv) { LogUtil.v(TAG, "Enabling respond via message intent"); } packageManager.setComponentEnabledSetting( new ComponentName(context, NoConfirmationSmsSendService.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { if (logv) { LogUtil.v(TAG, "Disabling respond via message intent"); } packageManager.setComponentEnabledSetting( new ComponentName(context, NoConfirmationSmsSendService.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } }
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// w w w . j ava 2 s. co 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: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);// w ww . j a va 2s . 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); } } }
From source file:co.edu.uniajc.vtf.content.NavigationActivity.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); LatLng loDestiny = new LatLng(this.coDestiny.getLatitude(), this.coDestiny.getLongitude()); if (this.coCurrentPosition != null) { coLatlngBounds = createLatLngBoundsObject(this.coCurrentPosition, loDestiny); coMap.moveCamera(CameraUpdateFactory.newLatLngBounds(coLatlngBounds, ciWidth, ciHeight, 150)); }/*from www .j a v a 2s . c o m*/ }
From source file:com.appsaur.tarucassist.AlarmReceiver.java
public void setAlarm(Context context, Calendar calendar, int ID) { 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 time Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using notification time mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, 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.farmerbb.taskbar.fragment.AdvancedFragment.java
@SuppressLint("SetTextI18n") @Override//from www .j a v a2 s.co m public boolean onPreferenceClick(final Preference p) { final SharedPreferences pref = U.getSharedPreferences(getActivity()); switch (p.getKey()) { case "clear_pinned_apps": Intent clearIntent = null; switch (pref.getString("theme", "light")) { case "light": clearIntent = new Intent(getActivity(), ClearDataActivity.class); break; case "dark": clearIntent = new Intent(getActivity(), ClearDataActivityDark.class); break; } startActivity(clearIntent); break; case "launcher": if (U.canDrawOverlays(getActivity())) { ComponentName component = new ComponentName(getActivity(), HomeActivity.class); getActivity().getPackageManager().setComponentEnabledSetting(component, ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } else { U.showPermissionDialog(getActivity()); ((CheckBoxPreference) p).setChecked(false); } if (!((CheckBoxPreference) p).isChecked()) LocalBroadcastManager.getInstance(getActivity()) .sendBroadcast(new Intent("com.farmerbb.taskbar.KILL_HOME_ACTIVITY")); break; case "keyboard_shortcut": ComponentName component = new ComponentName(getActivity(), KeyboardShortcutActivity.class); getActivity().getPackageManager() .setComponentEnabledSetting(component, ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); break; case "dashboard_grid_size": AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LinearLayout dialogLayout = (LinearLayout) View.inflate(getActivity(), R.layout.dashboard_size_dialog, null); boolean isPortrait = getActivity().getApplicationContext().getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; boolean isLandscape = getActivity().getApplicationContext().getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; int editTextId = -1; int editText2Id = -1; if (isPortrait) { editTextId = R.id.fragmentEditText2; editText2Id = R.id.fragmentEditText1; } if (isLandscape) { editTextId = R.id.fragmentEditText1; editText2Id = R.id.fragmentEditText2; } final EditText editText = (EditText) dialogLayout.findViewById(editTextId); final EditText editText2 = (EditText) dialogLayout.findViewById(editText2Id); builder.setView(dialogLayout).setTitle(R.string.dashboard_grid_size) .setPositiveButton(R.string.action_ok, (dialog, id) -> { boolean successfullyUpdated = false; String widthString = editText.getText().toString(); String heightString = editText2.getText().toString(); if (widthString.length() > 0 && heightString.length() > 0) { int width = Integer.parseInt(widthString); int height = Integer.parseInt(heightString); if (width > 0 && height > 0) { SharedPreferences.Editor editor = pref.edit(); editor.putInt("dashboard_width", width); editor.putInt("dashboard_height", height); editor.apply(); updateDashboardGridSize(true); successfullyUpdated = true; } } if (!successfullyUpdated) U.showToast(getActivity(), R.string.invalid_grid_size); }).setNegativeButton(R.string.action_cancel, null); editText.setText(Integer.toString(pref.getInt("dashboard_width", getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_width)))); editText2.setText(Integer.toString(pref.getInt("dashboard_height", getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_height)))); AlertDialog dialog = builder.create(); dialog.show(); new Handler().post(() -> { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText2, InputMethodManager.SHOW_IMPLICIT); }); break; case "navigation_bar_buttons": Intent intent = null; switch (pref.getString("theme", "light")) { case "light": intent = new Intent(getActivity(), NavigationBarButtonsActivity.class); break; case "dark": intent = new Intent(getActivity(), NavigationBarButtonsActivityDark.class); break; } startActivity(intent); break; } return true; }