List of usage examples for android.content.pm PackageManager setComponentEnabledSetting
public abstract void setComponentEnabledSetting(@NonNull ComponentName componentName, @EnabledState int newState, @EnabledFlags int flags);
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:co.carlosandresjimenez.android.gotit.notification.AlarmReceiver.java
/** * Cancels the alarm./*from w w w . j av a 2 s . co m*/ * * @param context */ public void cancelAlarm(Context context) { // If the alarm has been set, cancel it. if (alarmMgr != null) { alarmIntent.cancel(); alarmMgr.cancel(alarmIntent); } mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(NOTIFICATION_ID); 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:co.carlosandresjimenez.android.gotit.notification.AlarmReceiver.java
/** * Sets a repeating alarm that runs once a day at approximately 8:30 a.m. When the * alarm fires, the app broadcasts an Intent to this WakefulBroadcastReceiver. * * @param context//from ww w.j a v a 2s .com */ public void setAlarm(Context context) { // If the alarm has been set, cancel it. if (alarmMgr != null) { alarmIntent.cancel(); alarmMgr.cancel(alarmIntent); } alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); int userFrequencySetting = Utility.getNotificationFrequency(context); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.HOUR, userFrequencySetting); // Set the alarm to fire in X hours according to the device's // clock and user settings, and to repeat according to user settings alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), userFrequencySetting * ONE_HOUR_MILLISECONDS, alarmIntent); 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:ru.glesik.wifireminders.AlarmService.java
public void stopAlarm() { AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); alarmManager.cancel(pendingIntent);//from w w w . j a v a 2 s. co m // Disable boot receiver ComponentName receiver = new ComponentName(this, BootReceiver.class); PackageManager pm = this.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
public void setNotification() { NotificationItemClass notificationItemClass = new NotificationItemClass(); DataBaseHelper db = new DataBaseHelper(getActivity()); db.getWritableDatabase();/*from www. ja va2 s. 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.cognizant.trumobi.em.Email.java
public static void setServicesEnabled(Context context, boolean enabled) { PackageManager pm = context.getPackageManager(); if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, EmMailService.class)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { /*/* w ww. j a va 2 s .c o m*/ * If no accounts now exist but the service is still enabled we're * about to disable it so we'll reschedule to kill off any existing * alarms. */ EmMailService.actionReschedule(context); } pm.setComponentEnabledSetting(new ComponentName(context, EmMessageCompose.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(new ComponentName(context, EmAccountShortcutPicker.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(new ComponentName(context, EmMailService.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, EmMailService.class)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { /* * And now if accounts do exist then we've just enabled the service * and we want to schedule alarms for the new accounts. */ EmMailService.actionReschedule(context); } }
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.emotion.emotioncontrol.MainActivity.java
public void setLauncherIconEnabled(boolean enabled) { PackageManager p = getPackageManager(); int newState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; p.setComponentEnabledSetting(new ComponentName(this, LauncherActivity.class), newState, 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 . ja va 2 s . c o m 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.google.android.gms.location.sample.geofencing.GeofenceTransitionsIntentService.java
private void activateScanReceiver() { System.out.println("? ? ?"); ComponentName receiver = new ComponentName(this, WiFiScanReceiver.class); PackageManager pm = this.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }