List of usage examples for android.app AlarmManager RTC_WAKEUP
int RTC_WAKEUP
To view the source code for android.app AlarmManager RTC_WAKEUP.
Click Source Link
From source file:com.lambdasoup.quickfit.alarm.AlarmService.java
/** * sets the alarm with the alarm manager for the next occurrence of any scheduled event according * to the current db state//from w ww. j a v a 2 s.co m */ @WorkerThread private void setNextAlarm() { try (SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = db.rawQuery(QUERY_SELECT_MIN_NEXT_ALERT, null)) { // if cursor is empty, no schedules exist, no alarms to set if (cursor.moveToFirst()) { long nextAlarmMillis = cursor .getLong(cursor.getColumnIndexOrThrow(ScheduleEntry.COL_NEXT_ALARM_MILLIS)); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); PendingIntent alarmReceiverIntent = PendingIntent.getBroadcast(this, PENDING_INTENT_ALARM_RECEIVER, AlarmReceiver.getIntentOnAlarm(this), PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.cancel(alarmReceiverIntent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextAlarmMillis, alarmReceiverIntent); } else { alarmManager.setWindow(AlarmManager.RTC_WAKEUP, nextAlarmMillis, DateUtils.MINUTE_IN_MILLIS, alarmReceiverIntent); } } } }
From source file:com.nextgis.mobile.TrackerService.java
protected void ScheduleNextUpdate(Context context, String action, long nMinTimeBetweenSend, boolean bEnergyEconomy, boolean bStart) { if (context == null) return;/* w w w .j a va 2 s .com*/ Log.d(MainActivity.TAG, "Schedule Next Update for tracker " + bStart); if (bStart == false) return; Intent intent = new Intent(action); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // The update frequency should often be user configurable. This is not. long currentTimeMillis = System.currentTimeMillis(); long nextUpdateTimeMillis = currentTimeMillis + nMinTimeBetweenSend; Time nextUpdateTime = new Time(); nextUpdateTime.set(nextUpdateTimeMillis); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (bEnergyEconomy) alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent); else alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdateTimeMillis, pendingIntent); }
From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java
public static void addAlarm(Context context, Lecture lecture, int alarmTimesIndex) { int[] alarm_times = { 0, 5, 10, 15, 30, 45, 60 }; long when;/*from w w w. j a va 2 s . c o m*/ Time time; long startTime; long startTimeInSeconds = lecture.dateUTC; if (startTimeInSeconds > 0) { when = startTimeInSeconds; startTime = startTimeInSeconds; time = new Time(); } else { time = lecture.getTime(); startTime = time.normalize(true); when = time.normalize(true); } long alarmTimeDiffInSeconds = alarm_times[alarmTimesIndex] * 60 * 1000; when -= alarmTimeDiffInSeconds; // DEBUG // when = System.currentTimeMillis() + (30 * 1000); time.set(when); MyApp.LogDebug("addAlarm", "Alarm time: " + time.format("%Y-%m-%dT%H:%M:%S%z") + ", in seconds: " + when); Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(BundleKeys.ALARM_LECTURE_ID, lecture.lecture_id); intent.putExtra(BundleKeys.ALARM_DAY, lecture.day); intent.putExtra(BundleKeys.ALARM_TITLE, lecture.title); intent.putExtra(BundleKeys.ALARM_START_TIME, startTime); intent.setAction(AlarmReceiver.ALARM_LECTURE); intent.setData(Uri.parse("alarm://" + lecture.lecture_id)); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingintent = PendingIntent.getBroadcast(context, Integer.parseInt(lecture.lecture_id), intent, 0); // Cancel any existing alarms for this lecture alarmManager.cancel(pendingintent); // Set new alarm alarmManager.set(AlarmManager.RTC_WAKEUP, when, pendingintent); int alarmTimeInMin = alarm_times[alarmTimesIndex]; // write to DB AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(context); SQLiteDatabase db = alarmDB.getWritableDatabase(); // delete any previous alarms of this lecture try { db.beginTransaction(); db.delete(AlarmsTable.NAME, AlarmsTable.Columns.EVENT_ID + "=?", new String[] { lecture.lecture_id }); ContentValues values = new ContentValues(); values.put(AlarmsTable.Columns.EVENT_ID, Integer.parseInt(lecture.lecture_id)); values.put(AlarmsTable.Columns.EVENT_TITLE, lecture.title); values.put(AlarmsTable.Columns.ALARM_TIME_IN_MIN, alarmTimeInMin); values.put(AlarmsTable.Columns.TIME, when); DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); values.put(AlarmsTable.Columns.TIME_TEXT, df.format(new Date(when))); values.put(AlarmsTable.Columns.DISPLAY_TIME, startTime); values.put(AlarmsTable.Columns.DAY, lecture.day); db.insert(AlarmsTable.NAME, null, values); db.setTransactionSuccessful(); } catch (SQLException e) { } finally { db.endTransaction(); db.close(); } lecture.has_alarm = true; }
From source file:com.actinarium.nagbox.service.NagboxService.java
private void rescheduleAlarm() { AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Prepare pending intent. Setting, updating, or cancelling the alarm - we need it in either case Intent intent = new Intent(this, NagAlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); long nextTimestamp = NagboxDbOps.getClosestNagTimestamp(mDatabase); if (nextTimestamp == 0) { alarmManager.cancel(pendingIntent); } else {//www .ja v a 2 s. c o m // todo: deal with exact/inexact reminders later if (Build.VERSION.SDK_INT >= 23) { alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextTimestamp, pendingIntent); } else if (Build.VERSION.SDK_INT >= 19) { alarmManager.setWindow(AlarmManager.RTC_WAKEUP, nextTimestamp, ALARM_TOLERANCE, pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, nextTimestamp, pendingIntent); } } }
From source file:com.geotrackin.gpslogger.GpsLoggingService.java
/** * Sets up the auto email timers based on user preferences. *///from www . ja v a 2s. c o m public void SetupAutoSendTimers() { tracer.debug( "Setting up autosend timers. Auto Send Enabled - " + String.valueOf(AppSettings.isAutoSendEnabled()) + ", Auto Send Delay - " + String.valueOf(Session.getAutoSendDelay())); if (AppSettings.isAutoSendEnabled() && Session.getAutoSendDelay() > 0) { tracer.debug("Setting up autosend alarm"); long triggerTime = System.currentTimeMillis() + (long) (Session.getAutoSendDelay() * 60 * 60 * 1000); alarmIntent = new Intent(getApplicationContext(), AlarmReceiver.class); CancelAlarm(); PendingIntent sender = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, triggerTime, sender); tracer.debug("Autosend alarm has been set"); } else { if (alarmIntent != null) { tracer.debug("alarmIntent was null, canceling alarm"); CancelAlarm(); } } }
From source file:com.ksk.droidbatterybooster.provider.TimeSchedule.java
/** * Sets action in AlarmManger. This is what will * actually launch the action when the schedule triggers. * * @param schedule TimeSchedule./*from w w w .j a va 2 s. c om*/ * @param atTimeInMillis milliseconds since epoch */ @SuppressLint("NewApi") private static void enableAction(Context context, final TimeSchedule schedule, final long atTimeInMillis) { if (Log.LOGV) { Log.v("** setSchedule id " + schedule.id + " atTime " + atTimeInMillis); } Intent intent = new Intent(EXECUTE_SCHEDULE_ACTION); // XXX: This is a slight hack to avoid an exception in the remote // AlarmManagerService process. The AlarmManager adds extra data to // this Intent which causes it to inflate. Since the remote process // does not know about the TimeSchedule class, it throws a // ClassNotFoundException. // // To avoid this, we marshall the data ourselves and then parcel a plain // byte[] array. The ScheduleReceiver class knows to build the TimeSchedule // object from the byte[] array. Parcel out = Parcel.obtain(); schedule.writeToParcel(out, 0); out.setDataPosition(0); intent.putExtra(INTENT_RAW_DATA, out.marshall()); PendingIntent sender = PendingIntent.getBroadcast(context, schedule.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Utils.isKitKatOrLater()) { am.setExact(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender); } else { am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender); } Calendar c = Calendar.getInstance(); c.setTimeInMillis(atTimeInMillis); String timeString = formatDayAndTime(context, c); saveNextAlarm(context, timeString); }
From source file:com.atlas.mars.weatherradar.MainActivity.java
void morningAlarm() { //todo ? ?? //startService(new Intent(this, MorningService.class)); long time = db.getMorningWakeUp(); alarmManagerMorning = (AlarmManager) getSystemService(Context.ALARM_SERVICE); morningIntent = createIntent("morningAction", "extraMorning", MorningBroadCast.class); startService(morningIntent);//from w w w . j a v a2 s .co m pIntent2 = PendingIntent.getBroadcast(this, 0, morningIntent, PendingIntent.FLAG_CANCEL_CURRENT); alarmManagerMorning.cancel(pIntent2); alarmManagerMorning.set(AlarmManager.RTC_WAKEUP, time, pIntent2); //todo ? ? ?? // alarmManagerMorning.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+1*1000, pIntent2); }
From source file:com.mediatek.systemupdate.HttpManager.java
void notifyNewVersion() { if (Util.getUpdateType() == Util.UPDATE_TYPES.OTA_UPDATE_ONLY) { mDownloadInfo.setIfNeedRefresh(false); mDownloadInfo.setIfNeedRefreshMenu(true); Util.setAlarm(mContext, AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + Util.REFRESHTIME, Util.Action.ACTION_REFRESH_TIME_OUT); if (mHandler != null) { mHandler.sendMessage(mHandler.obtainMessage(SystemUpdateService.MSG_NOTIFY_QUERY_DONE)); Xlog.i(TAG, "onQueryNewVersion, Send new version founded message."); } else {/*w ww .ja v a 2s . c o m*/ mNotification.showNewVersionNotification(); } } }
From source file:com.jjcamera.apps.iosched.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID);//from w w w . j av a 2s . c om final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) { LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart); return; } // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData(new Uri.Builder().authority("com.jjcamera.apps.iosched") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); LOGD(TAG, "-> Intent extra: session start " + sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); LOGD(TAG, "-> Intent extra: session end " + sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:org.compose.mobilesdk.android.COMPOSESubService.java
/** * Schedules keep alives via a PendingIntent * in the Alarm Manager/*from w w w .j a v a2 s.c om*/ */ private void startKeepAlives() { Intent i = new Intent(); i.setClass(this, COMPOSESubService.class); i.setAction(ACTION_KEEPALIVE); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + MQTT_KEEP_ALIVE, MQTT_KEEP_ALIVE, pi); }