Java Code Examples for android.app.AlarmManager#setRepeating()
The following examples show how to use
android.app.AlarmManager#setRepeating() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WeatherAppWidget.java From LittleFreshWeather with Apache License 2.0 | 6 votes |
private static void setUpdateTimeAlarm(Context context, boolean on, final int updateSequency) { //LogUtil.e(TAG, "setUpdateTimeAlarm, on=" + on); Intent intent = new Intent(UPDATE_WIDGET_ACTION); intent.putExtra(UPDATE_TYPE, UPDATE_TIME); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); AlarmManager manager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); if (on) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { //LogUtil.e(TAG, "setRepeating"); manager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + updateSequency, updateSequency, pendingIntent); } else { //LogUtil.e(TAG, "setExact"); manager.setExact(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + updateSequency, pendingIntent); } } else { manager.cancel(pendingIntent); pendingIntent.cancel(); } }
Example 2
Source File: DeviceStartupIntentReceiver.java From product-emm with Apache License 2.0 | 6 votes |
/** * Initiates device notifier on device startup. * @param context - Application context. */ private void setRecurringAlarm(Context context) { this.resources = context.getApplicationContext().getResources(); String mode = Preference .getString(context, resources.getString(R.string.shared_pref_message_mode)); Float interval = (Float) Preference .getFloat(context, resources.getString(R.string.shared_pref_interval)); if (mode.trim().toUpperCase(Locale.ENGLISH).equals(NOTIFIER_MODE)) { long startTime = SystemClock.elapsedRealtime() + DEFAULT_TIME_MILLISECONDS; Intent alarmIntent = new Intent(context, AlarmReceiver.class); PendingIntent recurringAlarmIntent = PendingIntent.getBroadcast(context, DEFAULT_REQUEST_CODE, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, startTime, interval.intValue(), recurringAlarmIntent); } }
Example 3
Source File: MainActivity.java From TimeTable with GNU General Public License v3.0 | 6 votes |
private void setDailyAlarm() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); Calendar cur = Calendar.getInstance(); if (cur.after(calendar)) { calendar.add(Calendar.DATE, 1); } Intent myIntent = new Intent(this, DailyReceiver.class); int ALARM1_ID = 10000; PendingIntent pendingIntent = PendingIntent.getBroadcast( this, ALARM1_ID, myIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE); if (alarmManager != null) { alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); } }
Example 4
Source File: KlyphService.java From Klyph with MIT License | 6 votes |
public static void startBirthdayService() { Log.d("KlyphService", "Start birthday"); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MINUTE, 0); int currentHour = calendar.get(Calendar.HOUR_OF_DAY); int targetHour = KlyphPreferences.getBirthdayNotificationTime(); calendar.set(Calendar.HOUR_OF_DAY, targetHour); if (currentHour > targetHour) calendar.add(Calendar.DAY_OF_MONTH, 1); Intent service = new Intent(KlyphApplication.getInstance(), BirthdayService.class); PendingIntent pendingService = PendingIntent.getService(KlyphApplication.getInstance(), 0, service, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) KlyphApplication.getInstance() .getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingService); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingService); }
Example 5
Source File: AlarmService.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void onClick(View v) { // We want the alarm to go off 30 seconds from now. long firstTime = SystemClock.elapsedRealtime(); // Schedule the alarm! AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 30*1000, mAlarmSender); // Tell the user about what we did. Toast.makeText(AlarmService.this, R.string.repeating_scheduled, Toast.LENGTH_LONG).show(); }
Example 6
Source File: AlarmUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
public static void setRepeatingAlarm(Context context, PendingIntent pendingIntent, long time, long interval) { AlarmManager am = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); /* 设置周期闹钟 */ am.setRepeating(AlarmManager.RTC_WAKEUP, time, interval, pendingIntent); }
Example 7
Source File: AlarmManagerHelper.java From HouSi with Apache License 2.0 | 5 votes |
public static void setAlarmRepeat(Context context, long triggerAtMillis, long intervalMillis, PendingIntent intent) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { } alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, intervalMillis, intent); } }
Example 8
Source File: VibrateHelper.java From KUAS-AP-Material with MIT License | 5 votes |
public static void setCourseAlarm(Context context, String time, int dayOfWeek, int id, boolean isVibrate) { if (!time.contains(":")) { return; } Intent intent = new Intent(context, CourseVibrateAlarmService.class); Bundle bundle = new Bundle(); bundle.putBoolean("mode", isVibrate); intent.putExtras(bundle); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); calendar.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); calendar.set(Calendar.SECOND, 0); PendingIntent pendingIntent = PendingIntent.getService(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT); Date now = new Date(System.currentTimeMillis()); if (calendar.getTime().before(now)) { calendar.add(Calendar.DAY_OF_MONTH, 7); } AlarmManager alarm = (AlarmManager) context.getSystemService(Service.ALARM_SERVICE); alarm.cancel(pendingIntent); alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, pendingIntent); }
Example 9
Source File: OmahaClient.java From delion with Apache License 2.0 | 5 votes |
/** * Sets up a timer to fire after each interval. * Override to prevent a real alarm from being set. */ @VisibleForTesting protected void setAlarm(AlarmManager am, PendingIntent operation, int alarmType, long triggerAtTime) { try { am.setRepeating(AlarmManager.RTC, triggerAtTime, MS_BETWEEN_REQUESTS, operation); } catch (SecurityException e) { Log.e(TAG, "Failed to set repeating alarm."); } }
Example 10
Source File: OAuthHelperUtils.java From coinbase-bitmonet-sdk with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings("unused") private void setupRefreshAccessTokenListener() { Context context = Bitmonet.getBitmonetContext(); // Convert the time to ms int refreshTime = UserProfileSettings.getInstance().retrieveRefreshTime() * 1000; refreshTime = refreshTime - Constants.REFRESH_TIME_DELTA; context.registerReceiver(refreshTokenReceiver, new IntentFilter(Constants.ACCESS_TOKEN_RECV)); pi = PendingIntent.getBroadcast(context, 0, new Intent(Constants.ACCESS_TOKEN_RECV), 0); am = (AlarmManager) (context.getSystemService(Context.ALARM_SERVICE)); am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.currentThreadTimeMillis() + refreshTime, refreshTime, pi); }
Example 11
Source File: VibrateHelper.java From KUAS-AP-Material with MIT License | 5 votes |
public static void setCourseAlarm(Context context, String time, int dayOfWeek, int id, boolean isVibrate) { if (!time.contains(":")) { return; } Intent intent = new Intent(context, CourseVibrateAlarmService.class); Bundle bundle = new Bundle(); bundle.putBoolean("mode", isVibrate); intent.putExtras(bundle); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); calendar.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); calendar.set(Calendar.SECOND, 0); PendingIntent pendingIntent = PendingIntent.getService(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT); Date now = new Date(System.currentTimeMillis()); if (calendar.getTime().before(now)) { calendar.add(Calendar.DAY_OF_MONTH, 7); } AlarmManager alarm = (AlarmManager) context.getSystemService(Service.ALARM_SERVICE); alarm.cancel(pendingIntent); alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, pendingIntent); }
Example 12
Source File: AlarmManagerUtil.java From fingerpoetry-android with Apache License 2.0 | 5 votes |
/** * @param flag 周期性时间间隔的标志,flag = 0 表示一次性的闹钟, flag = 1 表示每天提醒的闹钟(1天的时间间隔),flag = 2 * 表示按周每周提醒的闹钟(一周的周期性时间间隔) * @param hour 时 * @param minute 分 * @param id 闹钟的id * @param week week=0表示一次性闹钟或者按天的周期性闹钟,非0 的情况下是几就代表以周为周期性的周几的闹钟 * @param tips 闹钟提示信息 * @param soundOrVibrator 2表示声音和震动都执行,1表示只有铃声提醒,0表示只有震动提醒 */ public static void setAlarm(Context context, int flag, int hour, int minute, int id, int week, String tips, int soundOrVibrator) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); long intervalMillis = 0; calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get (Calendar.DAY_OF_MONTH), hour, minute, 10); if (flag == 0) { intervalMillis = 0; } else if (flag == 1) { intervalMillis = 24 * 3600 * 1000; } else if (flag == 2) { intervalMillis = 24 * 3600 * 1000 * 7; } Intent intent = new Intent(ALARM_ACTION); intent.putExtra("intervalMillis", intervalMillis); intent.putExtra("msg", tips); intent.putExtra("id", id); intent.putExtra("soundOrVibrator", soundOrVibrator); PendingIntent sender = PendingIntent.getBroadcast(context, id, intent, PendingIntent .FLAG_CANCEL_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { am.setWindow(AlarmManager.RTC_WAKEUP, calMethod(week, calendar.getTimeInMillis()), intervalMillis, sender); } else { if (flag == 0) { am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender); } else { am.setRepeating(AlarmManager.RTC_WAKEUP, calMethod(week, calendar.getTimeInMillis ()), intervalMillis, sender); } } }
Example 13
Source File: PollingUtil.java From android-common with Apache License 2.0 | 5 votes |
/** * 开启轮询 */ @TargetApi(Build.VERSION_CODES.CUPCAKE) public static void startPolling(Context context, int mills, PendingIntent pendingIntent) { AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); manager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), mills, pendingIntent); }
Example 14
Source File: RemindersDao.java From narrate-android with Apache License 2.0 | 5 votes |
/** * Alarm Manager Methods */ public static boolean scheduleReminder(Reminder reminder) { if ( (System.currentTimeMillis() - reminder.date.getMillis()) > 0 ) return false; Intent intent = new Intent(reminder.uuid); intent.setClass(GlobalApplication.getAppContext(), AlarmReceiver.class); intent.putExtra("description", reminder.description); PendingIntent pendingIntent = PendingIntent.getBroadcast(GlobalApplication.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) GlobalApplication.getAppContext().getSystemService(GlobalApplication.getAppContext().ALARM_SERVICE); if ( reminder.recurring ) { long interval = 0; switch ( reminder.recurrence ) { case Daily: interval = DateUtil.DAY_IN_MILLISECONDS; am.setRepeating(AlarmManager.RTC_WAKEUP, reminder.date.getMillis(), interval, pendingIntent); break; case Weekly: interval = DateUtil.WEEK_IN_MILLISECONDS; am.setRepeating(AlarmManager.RTC_WAKEUP, reminder.date.getMillis(), interval, pendingIntent); break; case Monthly: am.set(AlarmManager.RTC_WAKEUP, reminder.date.plusMonths(1).getMillis(), pendingIntent); break; case Yearly: am.set(AlarmManager.RTC_WAKEUP, reminder.date.plusYears(1).getMillis(), pendingIntent); break; } } else { am.set(AlarmManager.RTC_WAKEUP, reminder.date.getMillis(), pendingIntent); } return true; }
Example 15
Source File: AlarmHelper.java From KUAS-AP-Material with MIT License | 5 votes |
public static void setCourseAlarm(Context context, String room, String title, String time, int dayOfWeek, int id) { if (!time.contains(":")) { return; } Intent intent = new Intent(context, CourseAlarmService.class); Bundle bundle = new Bundle(); bundle.putString("room", room); bundle.putString("title", title); bundle.putString("time", time); intent.putExtras(bundle); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); calendar.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); calendar.set(Calendar.SECOND, 0); calendar.add(Calendar.MINUTE, -10); PendingIntent pendingIntent = PendingIntent.getService(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT); Date now = new Date(System.currentTimeMillis()); if (calendar.getTime().before(now)) { calendar.add(Calendar.DAY_OF_MONTH, 7); } AlarmManager alarm = (AlarmManager) context.getSystemService(Service.ALARM_SERVICE); alarm.cancel(pendingIntent); alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, pendingIntent); }
Example 16
Source File: UpdateAlarm.java From odm with GNU General Public License v3.0 | 5 votes |
public void SetAlarm(Context context) { alarmContext = context; loadVARs(alarmContext); Logd(TAG, "Setting update alarm."); CancelAlarm(alarmContext); Long time = new GregorianCalendar().getTimeInMillis() + 1000 * 60 * 60 * 24 * 7; AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(alarmContext, UpdateAlarm.class); PendingIntent pi = PendingIntent.getBroadcast(alarmContext, 98, i, PendingIntent.FLAG_UPDATE_CURRENT); am.setRepeating(AlarmManager.RTC_WAKEUP, time, 1000 * 60 * 60 * 24 * 7, pi); // Millisec * Second * Minute * Hour * Days //am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+1000*60, 1000 * 60, pi); // Millisec * Second * Minute * Hour * Days }
Example 17
Source File: AlarmController.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void onClick(View v) { // When the alarm goes off, we want to broadcast an Intent to our // BroadcastReceiver. Here we make an Intent with an explicit class // name to have our own receiver (which has been published in // AndroidManifest.xml) instantiated and called, and then create an // IntentSender to have the intent executed as a broadcast. // Note that unlike above, this IntentSender is configured to // allow itself to be sent multiple times. Intent intent = new Intent(AlarmController.this, RepeatingAlarm.class); PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this, 0, intent, 0); // We want the alarm to go off 30 seconds from now. long firstTime = SystemClock.elapsedRealtime(); firstTime += 15*1000; // Schedule the alarm! AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 15*1000, sender); // Tell the user about what we did. if (mToast != null) { mToast.cancel(); } mToast = Toast.makeText(AlarmController.this, R.string.repeating_scheduled, Toast.LENGTH_LONG); mToast.show(); }
Example 18
Source File: PollingUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
public static void startPolling(Context context, String action, int seconds) { final AlarmManager manager = (AlarmManager) context. getSystemService(Context.ALARM_SERVICE); final Intent intent = new Intent(context, ClanService.class); intent.setAction(action); final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); final long triggerAtTime = SystemClock.elapsedRealtime(); manager.setRepeating(AlarmManager.ELAPSED_REALTIME, triggerAtTime, seconds * 1000, pendingIntent); }
Example 19
Source File: AlarmUtil.java From react-native-alarm-notification with MIT License | 4 votes |
void snoozeAlarm(AlarmModel alarm) { Calendar calendar = new GregorianCalendar(); calendar.set(Calendar.HOUR_OF_DAY, alarm.getHour()); calendar.set(Calendar.MINUTE, alarm.getMinute()); calendar.set(Calendar.SECOND, alarm.getSecond()); calendar.set(Calendar.DAY_OF_MONTH, alarm.getDay()); calendar.set(Calendar.MONTH, alarm.getMonth() - 1); calendar.set(Calendar.YEAR, alarm.getYear()); // set snooze interval calendar.add(Calendar.MINUTE, alarm.getSnoozeInterval()); alarm.setSecond(calendar.get(Calendar.SECOND)); alarm.setMinute(calendar.get(Calendar.MINUTE)); alarm.setHour(calendar.get(Calendar.HOUR_OF_DAY)); alarm.setDay(calendar.get(Calendar.DAY_OF_MONTH)); alarm.setMonth(calendar.get(Calendar.MONTH) - 1); alarm.setYear(calendar.get(Calendar.YEAR)); alarm.setAlarmId((int) System.currentTimeMillis()); getAlarmDB().update(alarm); Log.e(TAG, "snooze data - " + alarm.toString()); int alarmId = alarm.getAlarmId(); Intent intent = new Intent(mContext, AlarmReceiver.class); intent.putExtra("intentType", ADD_INTENT); intent.putExtra("PendingId", alarm.getId()); PendingIntent alarmIntent = PendingIntent.getBroadcast(mContext, alarmId, intent, 0); AlarmManager alarmManager = this.getAlarmManager(); String scheduleType = alarm.getScheduleType(); if (scheduleType.equals("once")) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent); } } else if (scheduleType.equals("repeat")) { alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarm.getInterval() * 1000, alarmIntent); } else { Log.d(TAG, "Schedule type should either be once or repeat"); } }
Example 20
Source File: NotificationTiming.java From iSCAU-Android with GNU General Public License v3.0 | 4 votes |
public void setNotification(){ am = (AlarmManager)this.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this,NotificationReceiver.class); pi = PendingIntent.getBroadcast(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT); am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + howlong, dailytime, pi); }