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:Main.java
public static void setAlarmTime(Context context, long timeInMillis, Intent intent) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent sender = PendingIntent.getBroadcast(context, intent.getIntExtra("id", 0), intent, PendingIntent.FLAG_CANCEL_CURRENT); int interval = (int) intent.getLongExtra("intervalMillis", 0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { am.setWindow(AlarmManager.RTC_WAKEUP, timeInMillis, interval, sender); }//from www. j av a 2 s .c o m }
From source file:Main.java
public static void setAlarm(Context context, Intent intent, int notificationId, Calendar calendar) { intent.putExtra("NOTIFICATION_ID", notificationId); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);/* www .j a v a2s.com*/ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } }
From source file:Main.java
public static void setTimerReceiver(Context context, int repeat_time, Class<?> class_name) { AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intentReceiver = new Intent(context, class_name); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentReceiver, PendingIntent.FLAG_CANCEL_CURRENT); Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, repeat_time / 1000); // InexactRepeating allows Android to optimize the energy consumption alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), repeat_time, pendingIntent); }
From source file:Main.java
public static PendingIntent scheduleLocalNotification(Context context, int slot, Long alertTime, String titleText, String subtitleText, String messageBodyText, String tickerText) { Log.i(TAG, "Scheduling local notification"); Intent alertIntent = new Intent(getNotificationName(slot)); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent); }/* www . j a v a2s.c o m*/ return pendingIntent; }
From source file:Main.java
public static void setupNotificationMessage(AlarmManager am, Calendar calendar, int interval, PendingIntent sender) {//from w w w .jav a 2 s . co m // official docs: // Note: as of API 19, all repeating alarms are inexact. If your application needs precise // delivery times then it must use one-time exact alarms, rescheduling each time as described above. // Legacy applications whosetargetSdkVersion is earlier than API 19 will continue to have all of their alarms, including repeating alarms, treated as exact. if (Build.VERSION.SDK_INT >= FAKE_KITKAT_WATCH) { //am.setWindow(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 20000, sender); am.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender); } else { // use this on sdk level 18 and smaller than 18. later sdk won`t guarantee time to be precise. //am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), interval, sender); am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender); } }
From source file:Main.java
public static PendingIntent scheduleLocalNotification(Context context, int slot, String title, String message, Long alertTime, int repeat) { Log.i(TAG, "Scheduling local notification"); Intent alertIntent = new Intent(getNotificationName(slot)); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { if (repeat == 0) { alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent); } else {/*from w w w. j av a 2 s . c om*/ Calendar alarmStartTime = Calendar.getInstance(); alarmStartTime.add(Calendar.MINUTE, 1); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alertTime, repeat, pendingIntent); } } return pendingIntent; }
From source file:Main.java
public static void startAlert(AlarmManager alarmMgr, PendingIntent alarmIntent, Context context) { // alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); // Intent intent = new Intent(context, AlerReceiver.class); // alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); // Set the alarm to start at 8:30 a.m. // Calendar calendar = Calendar.getInstance(); // calendar.setTimeInMillis(System.currentTimeMillis()); // calendar.set(Calendar.HOUR_OF_DAY, 8); // calendar.set(Calendar.MINUTE, 30); // setRepeating() lets you specify a precise custom interval--in this case, // 20 minutes. // alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), // 1000 * 60 * 20, alarmIntent); alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 3000, alarmIntent); }
From source file:Main.java
private static long setUpAlarm(AlarmManager alarmManager, PendingIntent pi, long timeInterval) { long curTime; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final AlarmManager.AlarmClockInfo alarmClockInfo = new AlarmManager.AlarmClockInfo( (curTime = System.currentTimeMillis()) + timeInterval, pi); alarmManager.setAlarmClock(alarmClockInfo, pi); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, (curTime = System.currentTimeMillis()) + timeInterval, pi);/*from w ww. j a v a 2 s .c om*/ } else { alarmManager.set(AlarmManager.RTC_WAKEUP, (curTime = System.currentTimeMillis()) + timeInterval, pi); } return curTime; }
From source file:com.tealeaf.PushBroadcastReceiver.java
public static void scheduleNext(Context context, int timeout) { TeaLeafOptions options = new TeaLeafOptions(context); String appID = options.getAppID(); logger.log("{push} Scheduling the next push for", timeout); Intent intent = new Intent("com.tealeaf.CHECK_PUSH_SERVER"); intent.putExtra("appID", appID); AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); scheduledIntent = PendingIntent.getBroadcast(context, 0, intent, 0); alarms.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (timeout * 1000), scheduledIntent); }
From source file:de.escoand.readdaily.ReminderHandler.java
public static void startReminder(final Context context, final int hour, final int minute) { Intent intent = new Intent(context, ReminderHandler.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE); GregorianCalendar cal = new GregorianCalendar(); // get next reminder cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, 0);//from w ww .j av a2s. c o m cal.set(Calendar.MILLISECOND, 0); if (cal.before(Calendar.getInstance())) cal.add(Calendar.DATE, 1); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 24 * 60 * 60 * 1000, pendingIntent); LogHandler.log(Log.WARN, "activated " + hour + ":" + minute); }