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:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.receiver.NotificationHelper.java
/** * Schedules to be woken up at the next notification time. *//*from ww w .j av a2 s.c o m*/ private static void scheduleNext(Context context) { // Get first future notification final Calendar now = Calendar.getInstance(); final List<cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification> notifications = cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification .getNotificationsWithTime(context, now.getTimeInMillis(), false); // if not empty, schedule alarm wake up if (!notifications.isEmpty()) { // at first's time // Create a new PendingIntent and add it to the AlarmManager Intent intent = new Intent(Intent.ACTION_RUN); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(pendingIntent); am.set(AlarmManager.RTC_WAKEUP, notifications.get(0).time, pendingIntent); } monitorUri(context); }
From source file:org.mariotaku.twidere.service.TwidereService.java
public boolean startAutoRefresh() { mAlarmManager.cancel(mPendingRefreshIntent); if (mPreferences.getBoolean(PREFERENCE_KEY_AUTO_REFRESH, false)) { final long update_interval = parseInt(mPreferences.getString(PREFERENCE_KEY_REFRESH_INTERVAL, "30")) * 60 * 1000;//from www .j av a 2 s. co m if (update_interval <= 0) return false; mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + update_interval, update_interval, mPendingRefreshIntent); return true; } return false; }
From source file:org.hopestarter.wallet.WalletApplication.java
public static void scheduleStartBlockchainService(final Context context) { final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context), context.getResources());/*from w ww .ja v a2s. c o m*/ final long lastUsedAgo = config.getLastUsedAgo(); // apply some backoff final long alarmInterval; if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS) alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES; else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS) alarmInterval = AlarmManager.INTERVAL_HALF_DAY; else alarmInterval = AlarmManager.INTERVAL_DAY; log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes", lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS); final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(context, 0, new Intent(context, BlockchainServiceImpl.class), 0); alarmManager.cancel(alarmIntent); // workaround for no inexact set() before KitKat final long now = System.currentTimeMillis(); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY, alarmIntent); }
From source file:org.smssecure.smssecure.notifications.MessageNotifier.java
private static void scheduleReminder(Context context, int count) { if (count >= SilencePreferences.getRepeatAlertsCount(context)) { return;/* www.j a va 2 s. com*/ } AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION); alarmIntent.putExtra("reminder_count", count); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT); long timeout = TimeUnit.MINUTES.toMillis(2); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent); }
From source file:org.kaoriha.phonegap.plugins.releasenotification.Notifier.java
private void schedule(long after) { Intent intent = new Intent(ctx, Receiver.class); PendingIntent pi = PendingIntent.getBroadcast(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + after, pi); }
From source file:com.google.android.apps.paco.NotificationCreator.java
private void createAlarmForSnooze(Context context, NotificationHolder notificationHolder) { DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime()); Experiment experiment = experimentProviderUtil.getExperiment(notificationHolder.getExperimentId()); Integer snoozeTime = experiment.getSignalingMechanisms().get(0).getSnoozeTime(); int snoozeMinutes = snoozeTime / MILLIS_IN_MINUTE; DateTime timeoutMinutes = new DateTime(alarmTime).plusMinutes(snoozeMinutes); long snoozeDurationInMillis = timeoutMinutes.getMillis(); Log.i(PacoConstants.TAG,/*from ww w .ja v a 2s . c o m*/ "Creating snooze alarm to resound notification for holder: " + notificationHolder.getId() + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = " + new DateTime(alarmTime).toString() + " waking up from snooze in " + timeoutMinutes + " minutes"); Intent ultimateIntent = new Intent(context, AlarmReceiver.class); Uri uri = Uri.withAppendedPath(NotificationHolderColumns.CONTENT_URI, notificationHolder.getId().toString()); ultimateIntent.setData(uri); ultimateIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue()); ultimateIntent.putExtra(SNOOZE_REPEATER_EXTRA_KEY, true); PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 3, ultimateIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(intent); alarmManager.set(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent); }
From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java
public void startServerHearBeatAlarm() { if (heartBitIntent != null) { alarmManager.cancel(heartBitIntent); //return; }/*from w w w . ja v a 2 s . c o m*/ heartBitIntent = null; //serverHeartBit=60*1000; //if (!mDaemon.notUrgent) serverHeartBit=10*1000; Intent jIntent = new Intent(this, ConnectDaemonService.class); //M1-00 (cool) or M1-01 (warm) jIntent.putExtra(ConnectDaemonService.ALARM_DONE, ALARM_BIT); heartBitIntent = PendingIntent.getService(this, ++heartBitRequestId % 100 + 1000, jIntent, PendingIntent.FLAG_ONE_SHOT); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + serverHeartBit, heartBitIntent); Log.i("ALARM_SET", "restart new alarm set for " + serverHeartBit / 1000 + " seconds"); //mDaemon.hasCommand=true; //mDaemon.interrupt(); }
From source file:org.apps8os.motivator.ui.MainActivity.java
/** * Set the notifications for the first time. After this, the notifications are controlled from the settings activity. *//* w w w . j ava 2s . c om*/ public void setNotifications() { // Set up notifying user to answer to the mood question // The time to notify the user Calendar notificationTime = Calendar.getInstance(); notificationTime.set(Calendar.MINUTE, 0); notificationTime.set(Calendar.SECOND, 0); // An alarm manager for scheduling notifications AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Set the notification to repeat over the given time at notificationTime Intent notificationIntent = new Intent(this, NotificationService.class); notificationIntent.putExtra(NotificationService.NOTIFICATION_TYPE, NotificationService.NOTIFICATION_MOOD); PendingIntent pendingNotificationIntent = PendingIntent.getService(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.cancel(pendingNotificationIntent); if (notificationTime.get(Calendar.HOUR_OF_DAY) >= 10) { notificationTime.add(Calendar.DATE, 1); } notificationTime.set(Calendar.HOUR_OF_DAY, 10); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingNotificationIntent); /** Commented out for now, setting different times for the notifications. if (mTimeToNotify == getString(R.string.in_the_morning_value)) { if (notificationTime.get(Calendar.HOUR_OF_DAY) >= 10) { notificationTime.add(Calendar.DATE, 1); } notificationTime.set(Calendar.HOUR_OF_DAY, 10); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingNotificationIntent); } else if (mTimeToNotify == getString(R.string.morning_and_evening_value)) { if (notificationTime.get(Calendar.HOUR_OF_DAY) >= 10 && notificationTime.get(Calendar.HOUR_OF_DAY) < 22) { notificationTime.set(Calendar.HOUR_OF_DAY, 22); } else if (notificationTime.get(Calendar.HOUR_OF_DAY) < 10) { notificationTime.set(Calendar.HOUR_OF_DAY, 10); } else { notificationTime.add(Calendar.DATE, 1); notificationTime.set(Calendar.HOUR_OF_DAY, 10); } alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_HALF_DAY, pendingNotificationIntent); } else if (mTimeToNotify == getString(R.string.every_hour_value)) { notificationTime.add(Calendar.HOUR_OF_DAY, 1); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, pendingNotificationIntent); } **/ }
From source file:opensource.zeocompanion.ZeoCompanionApplication.java
private void configAlarmManagerToPrefs() { // setup a daily alarm if auto-emailing is enabled SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean enabledAutoEmail = prefs.getBoolean("email_auto_enable", false); boolean enabledDatabaseReplicate = prefs.getBoolean("database_replicate_zeo", false); long desiredTOD = prefs.getLong("email_auto_send_time", 0); // will default to midnight long configuredTOD = prefs.getLong("email_auto_send_time_configured", 0); // will default to midnight // determine whether there is an active AlarmManager entry that we have established AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent intentCheck = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class); intentCheck.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC); PendingIntent existingPi = PendingIntent.getBroadcast(this, 0, intentCheck, PendingIntent.FLAG_NO_CREATE); if (enabledAutoEmail || enabledDatabaseReplicate) { // Daily AlarmManager is needed if (existingPi != null && desiredTOD != configuredTOD) { // there is an existing AlarmManager entry, but it has the incorrect starting time-of-day; // so cancel it, and rebuild a new one Intent intent1 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class); intent1.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC); PendingIntent pi1 = PendingIntent.getBroadcast(this, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(pi1);/* w w w . jav a2 s .co m*/ pi1.cancel(); existingPi = null; } if (existingPi == null) { // there is no existing AlarmManager entry, so create it Date dt = new Date(desiredTOD); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, dt.getHours()); calendar.set(Calendar.MINUTE, dt.getMinutes()); calendar.set(Calendar.SECOND, dt.getSeconds()); Intent intent2 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class); intent2.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC); PendingIntent pi2 = PendingIntent.getBroadcast(this, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT); am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi2); SharedPreferences.Editor editor = prefs.edit(); editor.putLong("email_auto_send_time_configured", desiredTOD); editor.commit(); } } else { // Daily AlarmManager is not needed if (existingPi != null) { // there is an AlarmManager entry pending; need to cancel it Intent intent3 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class); intent3.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC); PendingIntent pi3 = PendingIntent.getBroadcast(this, 0, intent3, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(pi3); pi3.cancel(); } } }
From source file:com.kaku.weac.fragment.AlarmClockOntimeFragment.java
/** * ??/*from w w w. ja v a 2s . c o m*/ */ @TargetApi(19) private void nap() { // ??X if (mNapTimesRan == mNapTimes) { return; } // ??1 mNapTimesRan++; LogUtil.d(LOG_TAG, "??" + mNapTimesRan); // ??? Intent intent = new Intent(getActivity(), AlarmClockBroadcast.class); intent.putExtra(WeacConstants.ALARM_CLOCK, mAlarmClock); intent.putExtra(WeacConstants.NAP_RAN_TIMES, mNapTimesRan); PendingIntent pi = PendingIntent.getBroadcast(getActivity(), -mAlarmClock.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Activity.ALARM_SERVICE); // XXX // ? long nextTime = System.currentTimeMillis() + 1000 * 60 * mNapInterval; LogUtil.i(LOG_TAG, "??:" + mNapInterval + ""); // ?194.4 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, nextTime, pi); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, nextTime, pi); } // ? Intent it = new Intent(getActivity(), AlarmClockNapNotificationActivity.class); it.putExtra(WeacConstants.ALARM_CLOCK, mAlarmClock); // FLAG_UPDATE_CURRENT ??? // FLAG_ONE_SHOT ?? PendingIntent napCancel = PendingIntent.getActivity(getActivity(), mAlarmClock.getId(), it, PendingIntent.FLAG_CANCEL_CURRENT); // CharSequence time = new SimpleDateFormat("HH:mm", Locale.getDefault()).format(nextTime); // NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity()); // PendingIntent Notification notification = builder.setContentIntent(napCancel) // ? .setDeleteIntent(napCancel) // .setContentTitle(String.format(getString(R.string.xx_naping), mAlarmClock.getTag())) // .setContentText(String.format(getString(R.string.nap_to), time)) // ??? .setTicker(String.format(getString(R.string.nap_time), mNapInterval)) // ??? .setSmallIcon(R.drawable.ic_nap_notification) // .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setAutoCancel(true) // ?? .setDefaults(NotificationCompat.DEFAULT_LIGHTS | NotificationCompat.FLAG_SHOW_LIGHTS).build(); /* notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS;*/ // ??? mNotificationManager.notify(mAlarmClock.getId(), notification); }