List of usage examples for android.content.pm PackageManager COMPONENT_ENABLED_STATE_ENABLED
int COMPONENT_ENABLED_STATE_ENABLED
To view the source code for android.content.pm PackageManager COMPONENT_ENABLED_STATE_ENABLED.
Click Source Link
From source file:eu.istvank.apps.lenslog.receivers.NotifyAlarmReceiver.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 w ww.j a v a2s. c o m*/ */ @TargetApi(Build.VERSION_CODES.KITKAT) public void setAlarm(Context context) { alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, NotifyAlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); // get notification time from preferences SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); long notificationTime = sp.getLong(SettingsFragment.KEY_PREF_NOTIFICATION_TIME, 50400000); Calendar calendar = Calendar.getInstance(); //TODO: if the time has passed already, set it to tomorrow. calendar.setTimeInMillis(notificationTime); // The following line is for debug only //alarmMgr.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent); // Set the alarm to fire according to the device's clock, and to repeat once a day. alarmMgr.setInexactRepeating(AlarmManager.RTC, notificationTime, AlarmManager.INTERVAL_DAY, alarmIntent); // Enable {@code SampleBootReceiver} to automatically restart the alarm when the // device is rebooted. ComponentName receiver = new ComponentName(context, NotifyAlarmReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
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); }//from ww w. j a v a 2 s.c o m }
From source file:cn.studyjams.s2.sj0119.NForget.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(ReminderEditActivity.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: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 ww . ja va 2s .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:com.appsaur.tarucassist.AutomuteAlarmReceiver.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, AutomuteAlarmReceiver.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.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 ww . j a va 2 s. 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.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 .java 2 s . co 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: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 ww w . j ava 2 s . c om 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 .co m }
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); }