Example usage for android.app AlarmManager RTC_WAKEUP

List of usage examples for android.app AlarmManager RTC_WAKEUP

Introduction

In this page you can find the example usage for android.app AlarmManager RTC_WAKEUP.

Prototype

int RTC_WAKEUP

To view the source code for android.app AlarmManager RTC_WAKEUP.

Click Source Link

Document

Alarm time in System#currentTimeMillis System.currentTimeMillis() (wall clock time in UTC), which will wake up the device when it goes off.

Usage

From source file:org.ozonecity.gpslogger2.GpsLoggingService.java

/**
 * Sets up the auto email timers based on user preferences.
 *//* w w  w  .j av a 2  s  . com*/
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) {
        long triggerTime = System.currentTimeMillis() + (long) (Session.getAutoSendDelay() * 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.android.calendar.alerts.AlarmScheduler.java

/**
 * Schedules an alarm for the EVENT_REMINDER_APP broadcast, for the specified
 * alarm time with a slight delay (to account for the possible duplicate broadcast
 * from the provider).//from  w  ww . ja  v  a2s  .c  o m
 */
private static void scheduleAlarm(Context context, long eventId, long alarmTime, long currentMillis,
        AlarmManagerInterface alarmManager) {
    // Max out the alarm time to 1 day out, so an alert for an event far in the future
    // (not present in our event query results for a limited range) can only be at
    // most 1 day late.
    long maxAlarmTime = currentMillis + MAX_ALARM_ELAPSED_MS;
    if (alarmTime > maxAlarmTime) {
        alarmTime = maxAlarmTime;
    }

    // Add a slight delay (see comments on the member var).
    alarmTime += ALARM_DELAY_MS;

    if (AlertService.DEBUG) {
        Time time = new Time();
        time.set(alarmTime);
        String schedTime = time.format("%a, %b %d, %Y %I:%M%P");
        Log.d(TAG, "Scheduling alarm for EVENT_REMINDER_APP broadcast for event " + eventId + " at " + alarmTime
                + " (" + schedTime + ")");
    }

    // Schedule an EVENT_REMINDER_APP broadcast with AlarmManager.  The extra is
    // only used by AlertService for logging.  It is ignored by Intent.filterEquals,
    // so this scheduling will still overwrite the alarm that was previously pending.
    // Note that the 'setClass' is required, because otherwise it seems the broadcast
    // can be eaten by other apps and we somehow may never receive it.
    Intent intent = new Intent(AlertReceiver.EVENT_REMINDER_APP_ACTION);
    intent.setClass(context, AlertReceiver.class);
    intent.putExtra(CalendarContract.CalendarAlerts.ALARM_TIME, alarmTime);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:com.smarthome.deskclock.Alarms.java

/**
 * Sets alert in AlarmManger and StatusBar.  This is what will
 * actually launch the alert when the alarm triggers.
 *
 * @param alarm Alarm./*from ww  w. java 2 s . c  om*/
 * @param atTimeInMillis milliseconds since epoch
 */
private static void enableAlert(Context context, final Alarm alarm, final long atTimeInMillis) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    if (Log.LOGV) {
        Log.v("** setAlert id " + alarm.id + " atTime " + atTimeInMillis);
    }

    Intent intent = new Intent(ALARM_ALERT_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 Alarm class, it throws a
    // ClassNotFoundException.
    //
    // To avoid this, we marshall the data ourselves and then parcel a plain
    // byte[] array. The AlarmReceiver class knows to build the Alarm
    // object from the byte[] array.
    Parcel out = Parcel.obtain();
    alarm.writeToParcel(out, 0);
    out.setDataPosition(0);
    intent.putExtra(ALARM_RAW_DATA, out.marshall());

    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender);

    setStatusBarIcon(context, true);

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(atTimeInMillis);
    String timeString = formatDayAndTime(context, c);
    saveNextAlarm(context, timeString);
}

From source file:org.mariotaku.twidere.service.RefreshService.java

private void rescheduleHomeTimelineRefreshing() {
    mAlarmManager.cancel(mPendingRefreshHomeTimelineIntent);
    final long refreshInterval = getRefreshInterval();
    if (refreshInterval > 0) {
        mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + refreshInterval,
                refreshInterval, mPendingRefreshHomeTimelineIntent);
    }//  w  ww. jav  a2s.co m
}

From source file:org.mariotaku.twidere.service.RefreshService.java

private void rescheduleMentionsRefreshing() {
    mAlarmManager.cancel(mPendingRefreshMentionsIntent);
    final long refreshInterval = getRefreshInterval();
    if (refreshInterval > 0) {
        mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + refreshInterval,
                refreshInterval, mPendingRefreshMentionsIntent);
    }//w  w  w .  j  a va 2s. com
}

From source file:com.crearo.gpslogger.GpsLoggingService.java

/**
 * Sets up the auto email timers based on user preferences.
 *//*from   w  w  w .j a va 2s  .  c  om*/
@TargetApi(23)
public void setupAutoSendTimers() {
    LOG.debug("Setting up autosend timers. Auto Send Enabled - "
            + String.valueOf(preferenceHelper.isAutoSendEnabled()) + ", Auto Send Delay - "
            + String.valueOf(Session.getAutoSendDelay()));

    if (preferenceHelper.isAutoSendEnabled() && Session.getAutoSendDelay() > 0) {
        long triggerTime = System.currentTimeMillis() + (long) (Session.getAutoSendDelay() * 60 * 1000);

        alarmIntent = new Intent(this, AlarmReceiver.class);
        cancelAlarm();

        PendingIntent sender = PendingIntent.getBroadcast(this, 0, alarmIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (Systems.isDozing(this)) {
            am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, sender);
        } else {
            am.set(AlarmManager.RTC_WAKEUP, triggerTime, sender);
        }
        LOG.debug("Autosend alarm has been set");

    } else {
        if (alarmIntent != null) {
            LOG.debug("alarmIntent was null, canceling alarm");
            cancelAlarm();
        }
    }
}

From source file:com.google.android.apps.paco.NotificationCreator.java

private void createAlarmToCancelNotificationAtTimeout(Context context, NotificationHolder notificationHolder) {
    DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime());
    int timeoutMinutes = (int) (notificationHolder.getTimeoutMillis() / MILLIS_IN_MINUTE);
    DateTime timeoutTime = new DateTime(alarmTime).plusMinutes(timeoutMinutes);
    long elapsedDurationInMillis = timeoutTime.getMillis();

    Log.i(PacoConstants.TAG,/*  w  w w . j a  v  a 2s.  c o m*/
            "Creating cancel alarm to timeout notification for holder: " + notificationHolder.getId()
                    + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = "
                    + new DateTime(alarmTime).toString() + " timing out 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());

    PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 2, ultimateIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(intent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, elapsedDurationInMillis, intent);
}

From source file:de.azapps.mirakel.reminders.ReminderAlarm.java

private static PendingIntent updateAlarm(final Context ctx, final Task task) {
    final Intent intent = new Intent(ctx, ReminderAlarm.class);
    intent.setAction(SHOW_TASK);//  w ww  .j  av a 2s .  co m
    intent.putExtra(EXTRA_ID, task.getId());
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    if ((pendingIntent == null) || !task.getReminder().isPresent()) {
        return null;
    }
    Log.v(TAG, "Set alarm for " + task.getName() + " on " + task.getReminder().get().getTimeInMillis());
    final Optional<Recurring> recurringReminder = task.getRecurringReminder();
    if (!recurringReminder.isPresent()) {
        alarmManager.set(AlarmManager.RTC_WAKEUP, task.getReminder().get().getTimeInMillis(), pendingIntent);
    } else {
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, task.getReminder().get().getTimeInMillis(),
                recurringReminder.get().getInterval(), pendingIntent);
    }
    return pendingIntent;
}

From source file:com.aero2.android.DefaultActivities.SmogMapActivity.java

public void setupAlarm(int hourOfDay) {
    //Alarm has been called
    ALARM_NOT_CALLED = false;/*w  ww.  j  a va 2  s.c  o  m*/

    //Setup what the alarm has to do when it goes off.
    Intent alarmIntent = new Intent(SmogMapActivity.this, AirAzureDownloadService.AlarmReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(SmogMapActivity.this, 0, alarmIntent,
            PendingIntent.FLAG_ONE_SHOT);//getBroadcast(context, 0, i, 0);
    Log.v("OnCreate", "Alarm Intent Created");

    //Set the AlarmManager to wake up the system every day at 6 a.m.
    AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
    long timeEveryDay = calendar.getTimeInMillis();
    long currentTime = System.currentTimeMillis();
    long oneMin = 60 * 1000;
    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeEveryDay, AlarmManager.INTERVAL_DAY, pi);
    if ((currentTime + oneMin) < timeEveryDay) {
        Log.v(LOG_TAG, "First time download and time is before 6 a.m.");
        Intent firstTimeDownloadIntent = new Intent(getApplicationContext(), AirAzureDownloadService.class);
        startService(firstTimeDownloadIntent);
    }
}

From source file:org.mariotaku.twidere.service.RefreshService.java

private void rescheduleTrendsRefreshing() {
    mAlarmManager.cancel(mPendingRefreshTrendsIntent);
    final long refreshInterval = getRefreshInterval();
    if (refreshInterval > 0) {
        mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + refreshInterval,
                refreshInterval, mPendingRefreshTrendsIntent);
    }/* w ww.ja  v a 2s .  c o  m*/
}