List of usage examples for android.content Context ALARM_SERVICE
String ALARM_SERVICE
To view the source code for android.content Context ALARM_SERVICE.
Click Source Link
From source file:nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver.java
public AlarmReceiver() { Context context = GBApplication.getContext(); Intent intent = new Intent("DAILY_ALARM"); intent.setPackage(BuildConfig.APPLICATION_ID); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, new Intent("DAILY_ALARM"), 0); AlarmManager am = (AlarmManager) (context.getSystemService(Context.ALARM_SERVICE)); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 10000, AlarmManager.INTERVAL_DAY, pendingIntent); }
From source file:org.isoron.uhabits.helpers.ReminderHelper.java
public static void createReminderAlarm(Context context, Habit habit, @Nullable Long reminderTime) { if (!habit.hasReminder()) return;//from ww w . ja v a2 s . c om if (reminderTime == null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); //noinspection ConstantConditions calendar.set(Calendar.HOUR_OF_DAY, habit.reminderHour); //noinspection ConstantConditions calendar.set(Calendar.MINUTE, habit.reminderMin); calendar.set(Calendar.SECOND, 0); reminderTime = calendar.getTimeInMillis(); if (System.currentTimeMillis() > reminderTime) reminderTime += AlarmManager.INTERVAL_DAY; } long timestamp = DateHelper.getStartOfDay(DateHelper.toLocalTime(reminderTime)); Uri uri = habit.getUri(); Intent alarmIntent = new Intent(context, HabitBroadcastReceiver.class); alarmIntent.setAction(HabitBroadcastReceiver.ACTION_SHOW_REMINDER); alarmIntent.setData(uri); alarmIntent.putExtra("timestamp", timestamp); alarmIntent.putExtra("reminderTime", reminderTime); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, ((int) (habit.getId() % Integer.MAX_VALUE)) + 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Build.VERSION.SDK_INT >= 23) manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent); else if (Build.VERSION.SDK_INT >= 19) manager.setExact(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent); else manager.set(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent); String name = habit.name.substring(0, Math.min(3, habit.name.length())); Log.d("ReminderHelper", String.format("Setting alarm (%s): %s", DateFormat.getDateTimeInstance().format(new Date(reminderTime)), name)); }
From source file:org.dodgybits.shuffle.android.server.sync.SyncSchedulingService.java
@Override protected void onHandleIntent(Intent intent) { SyncState state = SyncState.restore(this); state.process(this, intent.getExtras()); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent syncIntent = new Intent(this, SyncReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP, state.nextScheduledSync, pendingIntent); // Release the wake lock provided by the WakefulBroadcastReceiver WakefulBroadcastReceiver.completeWakefulIntent(intent); }
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/* w w w .j av a2 s. 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.cryart.sabbathschool.util.SSNotification.java
public static void cancelRepeatingNotification(Context context) { AlarmManager _SSAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent _SSUpdateServiceIntent = new Intent(context, SSBroadcastReceiver.class); PendingIntent _SSPendingUpdateServiceIntent = PendingIntent.getBroadcast(context, 0, _SSUpdateServiceIntent, 0);//from ww w . j a va2s . c om try { _SSAlarmManager.cancel(_SSPendingUpdateServiceIntent); } catch (Exception e) { } }
From source file:com.daiv.android.twitter.services.TrimDataService.java
public void setNextTrim(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); long now = new Date().getTime(); long alarm = now + AlarmManager.INTERVAL_DAY; Log.v("alarm_date", "auto trim " + new Date(alarm).toString()); PendingIntent pendingIntent = PendingIntent.getService(context, TRIM_ID, new Intent(context, TrimDataService.class), 0); am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent); }
From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java
public ScheduledNotification scheduleNotification(String title, JSONObject options) { LOG.v(NotificationPlugin.TAG, "scheduleNotification: " + title); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); ScheduledNotification notification = new ScheduledNotification(title, options); long alarmTime = notification.at; if (alarmTime != 0) { //0 = uninitialized. saveNotification(notification);/*www .j ava 2 s. com*/ LOG.v(NotificationPlugin.TAG, "create Intent: " + notification.tag); Intent intent = new Intent(context, TriggerReceiver.class); intent.setAction(notification.tag); PendingIntent pi = PendingIntent.getBroadcast(context, INTENT_REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT); LOG.v(NotificationPlugin.TAG, "schedule alarm for: " + alarmTime); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTime, pi); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); } } else { // No "at", trigger the notification right now. showNotification(notification); } return notification; }
From source file:com.licenta.android.licenseapp.alarm.AlarmReceiver.java
public static void cancelAlarm(Context context) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); //if (alarmManager!= null) { alarmManager.cancel(alarmIntent);//from www.ja v a2s . c o m PreferenceManager.getDefaultSharedPreferences(context).edit() .putBoolean(Constants.PREF_KEY_IS_ALARM_ON, false).apply(); Log.d(context.getClass().getName(), "Alarm stopped"); //} }
From source file:com.oliversride.wordryo.UpdateCheckReceiver.java
public static void restartTimer(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, UpdateCheckReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); am.cancel(pi);//from w w w .jav a 2 s . c om long interval_millis = INTERVAL_ONEDAY; if (!devOK(context)) { interval_millis *= INTERVAL_NDAYS; } interval_millis = (interval_millis / 2) + Math.abs(Utils.nextRandomInt() % interval_millis); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + interval_millis, interval_millis, pi); }
From source file:com.conferenceengineer.android.iosched.gcm.command.SyncCommand.java
private void scheduleSync(Context context, int syncJitter) { int jitterMillis = (int) (RANDOM.nextFloat() * syncJitter); final String debugMessage = "Scheduling next sync for " + jitterMillis + "ms"; LOGI(TAG, debugMessage);/* ww w . ja v a 2s . c o m*/ ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).set(AlarmManager.RTC, System.currentTimeMillis() + jitterMillis, PendingIntent.getBroadcast(context, 0, new Intent(context, TriggerSyncReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT)); }