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.lloydtorres.stately.push.TrixHelper.java
/** * Sets an alarm for Alphys to query NS for new notices. The alarm time is on whatever the user * selected in settings, starting from the time the function was called. A "jitter" of up to * 5 minutes is added on top to prevent overwhelming the NS servers. * @param c App context//from w w w.j a v a 2 s . c om */ public static void setAlarmForAlphys(Context c) { // First check if alarms should be set to begin with. if (!SettingsActivity.getNotificationSetting(c)) { return; } Intent alphysIntent = new Intent(c, AlphysReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(c, 0, alphysIntent, PendingIntent.FLAG_UPDATE_CURRENT); long timeToNextAlarm = System.currentTimeMillis() + SettingsActivity.getNotificationIntervalSetting(c) * 1000L; // add "jitter" from 0 min to 5 min to next alarm to prevent overwhelming NS servers Random r = new Random(); timeToNextAlarm += (long) (r.nextDouble() * FIVE_MIN_IN_MS); // Source: // https://www.reddit.com/r/Android/comments/44opi3/reddit_sync_temporarily_blocked_for_bad_api_usage/czs3ne4 AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timeToNextAlarm, pendingIntent); } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { am.setExact(AlarmManager.RTC_WAKEUP, timeToNextAlarm, pendingIntent); } else { am.set(AlarmManager.RTC_WAKEUP, timeToNextAlarm, pendingIntent); } }
From source file:com.ayuget.redface.job.PrivateMessagesService.java
@TargetApi(android.os.Build.VERSION_CODES.KITKAT) @Override//from w w w . java2 s . co m protected void onHandleIntent(Intent intent) { Log.d(LOG_TAG, "Handling intent"); if (!settings.arePrivateMessagesNoticationsEnabled()) { return; } final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(getApplicationContext()); for (User redfaceUser : userManager.getRealUsers()) { subscriptions.add(mdService.getNewPrivateMessages(redfaceUser) .subscribe(new EndlessObserver<List<PrivateMessage>>() { @Override public void onNext(List<PrivateMessage> privateMessages) { for (PrivateMessage privateMessage : privateMessages) { // Prepare intent to deal with clicks Intent resultIntent = new Intent(PrivateMessagesService.this, PrivateMessagesActivity.class); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); resultIntent.putExtra(UIConstants.ARG_SELECTED_PM, privateMessage); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder( getApplicationContext()).setSmallIcon(R.drawable.ic_action_emo_wonder) .setColor(getResources().getColor(R.color.theme_primary)) .setContentTitle(privateMessage.getRecipient()) .setContentText(privateMessage.getSubject()) .setContentIntent(resultPendingIntent).setAutoCancel(true); builder.setVibrate(VIBRATION_PATTERN); notificationManager.notify((int) privateMessage.getId(), builder.build()); } } })); } // Setup next alarm long wakeUpTime = System.currentTimeMillis() + settings.getPrivateMessagesPollingFrequency() * DateUtils.MINUTE_IN_MILLIS; AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, PrivateMessagesService.class); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); Log.d(LOG_TAG, "Going to sleep, setting wake-up alarm to: " + wakeUpTime); if (AndroidUtils.isKitKatOrHigher()) { am.setExact(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } else { am.set(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } }
From source file:app.jorge.mobile.com.transportalert.ScrollingActivity.java
public void scheduleAlarm() { // Construct an intent that will execute the AlarmReceiver Intent intent = new Intent(getApplicationContext(), MyAlarmReceiver.class); // Create a PendingIntent to be triggered when the alarm goes off final PendingIntent pIntent = PendingIntent.getBroadcast(this, MyAlarmReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Setup periodic alarm every 5 seconds long firstMillis = System.currentTimeMillis(); // alarm is set right away AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); // First parameter is the type: ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC_WAKEUP // Interval can be INTERVAL_FIFTEEN_MINUTES, INTERVAL_HALF_HOUR, INTERVAL_HOUR, INTERVAL_DAY //alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstMillis, // AlarmManager.INTERVAL_HALF_HOUR, pIntent); alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstMillis, AlarmManager.INTERVAL_HALF_HOUR, pIntent); }
From source file:net.vexelon.bgrates.ui.activities.MainActivity.java
public void startService() { Intent myIntent = new Intent(MainActivity.this, RateService.class); pendingIntent = PendingIntent.getService(MainActivity.this, 0, myIntent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 30); long initialStartTimeout = calendar.getTimeInMillis(); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, initialStartTimeout, Defs.NOTIFY_INTERVAL, pendingIntent);//from w w w. j ava2s . c om }
From source file:com.firsttry.mumbaiparking.helpers.MyAlarmManager.java
public void setAlarm(Context context) { SharedPreferences prefs = context.getSharedPreferences("Reminders", 0); Calendar cal = Calendar.getInstance(); int currentDate = cal.get(cal.DATE); int currentMonth = cal.get(cal.MONTH); int currentYear = cal.get(cal.YEAR); int pucDate = prefs.getInt("PUC_DATE", 0); int pucMonth = prefs.getInt("PUC_MONTH", 0); int pucYear = prefs.getInt("PUC_YEAR", 0); int insuranceDate = prefs.getInt("INSURANCE_DATE", 0); int insuranceMonth = prefs.getInt("INSURANCE_MONTH", 0); int insuranceYear = prefs.getInt("INSURANCE_YEAR", 0); int licenseDate = prefs.getInt("LICENSE_DATE", 0); int licenseMonth = prefs.getInt("LICENSE_MONTH", 0); int licenseYear = prefs.getInt("LICENSE_YEAR", 0); AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, MyAlarmManager.class); Log.i("Dates", "PUC : " + pucDate + " " + pucMonth + " " + pucYear); Log.i("Dates", "Licence : " + licenseDate + " " + licenseMonth + " " + licenseYear); Log.i("Dates", "Insurance : " + insuranceDate + " " + insuranceMonth + " " + insuranceYear); Log.i("Dates", "current : " + currentDate + " " + currentMonth + " " + currentYear); if (pucDate != 0 && (pucMonth - currentMonth) == 0 && (pucYear - currentYear) == 0 && (pucDate - currentDate) < 7 && (pucDate - currentDate) >= 0) { Log.i("setAlarm", "Inside if puc"); i.putExtra("pucDays", (pucDate - currentDate)); }/*from w w w . j a va2 s. c o m*/ if (licenseDate != 0 && (licenseMonth - currentMonth) == 0 && (licenseYear - currentYear) == 0 && (licenseDate - currentDate) < 7 && (licenseDate - currentDate) >= 0) { Log.i("setAlarm", "Inside if license"); i.putExtra("licenseDays", (licenseDate - currentDate)); } if (insuranceDate != 0 && (insuranceMonth - currentMonth) == 0 && (insuranceYear - currentYear) == 0 && (insuranceDate - currentDate) < 7 && (insuranceDate - currentDate) >= 0) { Log.i("setAlarm", "Inside if insurance"); //i.putExtra("type", "Insurance"); i.putExtra("insuranceDays", (insuranceDate - currentDate)); } PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 10, pi); }
From source file:com.iitb.wicroft.EventAlarmReceiver.java
void scheduleNextAlarm(Context context) { String msg = "EventAlarmeceiver - ScheduleNextAlarm "; if (!MainActivity.running) { msg += "scheduleNextAlarm : Experiment not 'running'"; return;/*from ww w . j a v a2s.c o m*/ } if (MainActivity.load == null) { msg += "scheduleNextAlarm : load null"; return; } if (MainActivity.currEvent >= MainActivity.load.independent_events.size()) { msg += "scheduleNextAlarm : All independent events alarms over."; return; } // RequestEvent e = MainActivity.load.events.get(MainActivity.currEvent); Log.d("EventAlarmRx :nextalarm", " MainActivity.currEvent = " + MainActivity.currEvent); RequestEvent e = new RequestEvent(MainActivity.load.independent_events.get(MainActivity.currEvent)); Intent intent = new Intent(context, EventAlarmReceiver.class); intent.putExtra("eventid", (int) e.event_id); Random r = new Random(); int i1 = r.nextInt(10000 - 0) + 0; PendingIntent sender = PendingIntent.getBroadcast(context, Constants.alarmRequestCode + i1, intent, PendingIntent.FLAG_UPDATE_CURRENT); msg += "\n e.cal time in millisec : " + Long.toString(e.cal.getTimeInMillis()) + "MainActivity.serverTimeDelta : " + Long.toString(MainActivity.serverTimeDelta); msg += "\n Scheduling " + e.event_id + "@" + MainActivity.sdf.format(e.cal.getTime()); msg += "\n current time in ms :" + Long.toString(Calendar.getInstance().getTimeInMillis()); msg += "\n alarmwakeup in ms" + Long.toString(e.cal.getTimeInMillis() - MainActivity.serverTimeDelta); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { // Do something for kitkat and above versions MainActivity.am.setExact(AlarmManager.RTC_WAKEUP, e.cal.getTimeInMillis() - MainActivity.serverTimeDelta, sender); } else { // do something for phones running an SDK before kitkat MainActivity.am.set(AlarmManager.RTC_WAKEUP, e.cal.getTimeInMillis() - MainActivity.serverTimeDelta, sender); } // Log.d(Constants.LOGTAG, MainActivity.sdf.format(cal.getTime()) + "Scheduling " + MainActivity.currEvent + "@" + MainActivity.sdf.format(e.cal.getTime()) + "\n"); /* * [event_time_stamp - (server - local)] gives when alarm should be scheduled. * Why ? Details ahead : * For e.g if local 2.00, server 2.10. Difference (server - local) = 10 * Now server says schedule alarm at 2.15. Alarms follow local time. * So now according to local time, alarm should be scheduled at * time 2.05 (because at that moment servertime will be 2.05 + 10 = 2.15) */ MainActivity.currEvent++; // Log.d(Constants.LOGTAG, "Current event" + MainActivity.currEvent); Log.d(Constants.LOGTAG, msg); if (MainActivity.debugging_on) { Calendar cal = Calendar.getInstance(); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); Threads.writeToLogFile(MainActivity.debugfilename, format1.format(cal.getTime()) + " " + Utils.sdf.format(cal.getTime()) + msg); } }
From source file:com.google.android.apps.iosched.calendar.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);// www . j a va2 s . c om final long currentTime = System.currentTimeMillis(); // If the session is already started, do not schedule system notification. if (currentTime > 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 - TEN_MINUTES_MILLIS; } else { alarmTime = currentTime + alarmOffset; } final Intent alarmIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. alarmIntent.setData(new Uri.Builder().authority(ScheduleContract.CONTENT_AUTHORITY) .path(String.valueOf(sessionStart)).build()); alarmIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); alarmIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); alarmIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. am.set(AlarmManager.RTC_WAKEUP, alarmTime, PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT)); }
From source file:ua.org.gdg.devfest.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 a v a2 s .com*/ final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > 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; } 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("ua.org.gdg.devfest.iosched") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); notifIntent.putExtra(SessionAlarmService.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. am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:com.conferenceengineer.android.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 a v a 2s . c o m final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > 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; } 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.conferenceengineer.android.iosched") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); notifIntent.putExtra(SessionAlarmService.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. am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:it.gulch.linuxday.android.services.AlarmIntentService.java
private void updateAlarms(Intent intent) { // Create/update all alarms try {/*from www .j av a 2 s.c o m*/ long delay = getDelay(); Date nowDate = new Date(); long now = nowDate.getTime(); List<Bookmark> bookmarks = bookmarkManager.getBookmarks(nowDate); for (Bookmark bookmark : bookmarks) { Event event = bookmark.getEvent(); long notificationTime = event.getStartDate().getTime() - delay; PendingIntent pendingIntent = getAlarmPendingIntent(event.getId()); if (notificationTime < now) { // Cancel pending alarms that where scheduled between now and delay, if any alarmManager.cancel(pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, notificationTime, pendingIntent); } } // Release the wake lock setup by AlarmReceiver, if any if (intent.getBooleanExtra(EXTRA_WITH_WAKE_LOCK, false)) { AlarmReceiver.completeWakefulIntent(intent); } } catch (SQLException e) { Log.e(TAG, e.getMessage(), e); } }