Example usage for android.app AlarmManager ELAPSED_REALTIME_WAKEUP

List of usage examples for android.app AlarmManager ELAPSED_REALTIME_WAKEUP

Introduction

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

Prototype

int ELAPSED_REALTIME_WAKEUP

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

Click Source Link

Document

Alarm time in android.os.SystemClock#elapsedRealtime SystemClock.elapsedRealtime() (time since boot, including sleep), which will wake up the device when it goes off.

Usage

From source file:gpsalarm.app.service.PostMonitor.java

private void setAlarm(long period) {
    alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi);
}

From source file:org.ohmage.reminders.types.location.LocTrigService.java

private void setTriggerAlwaysAlarm(int trigId, String trigDesc) {

    cancelTriggerAlwaysAlarm(trigId);//  w  w w.ja v  a  2 s  .c om

    LocTrigDesc desc = new LocTrigDesc();
    if (!desc.loadString(trigDesc)) {
        return;
    }

    if (!desc.shouldTriggerAlways()) {
        return;
    }

    Log.v(TAG, "LocTrigService: Setting trigger always alarm(" + trigId + ", " + trigDesc + ")");

    Calendar target = Calendar.getInstance();
    target.set(Calendar.HOUR_OF_DAY, desc.getEndTime().getHour());
    target.set(Calendar.MINUTE, desc.getEndTime().getMinute());
    target.set(Calendar.SECOND, 0);

    LocationTrigger locTrig = new LocationTrigger();
    if (locTrig.hasTriggeredToday(this, trigId)) {
        target.add(Calendar.DAY_OF_YEAR, 1);
    } else if (System.currentTimeMillis() >= target.getTimeInMillis()) {
        target.add(Calendar.DAY_OF_YEAR, 1);
    }

    Intent i = createTriggerAlwaysAlarmIntent(trigId);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

    AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE);

    Log.v(TAG, "LocTrigService: Calculated target time: " + target.getTime().toString());

    long alarmTime = target.getTimeInMillis();

    /* Convert the alarm time to elapsed real time.
     * If we dont do this, a time change in the system might
     * set off all the alarms and a trigger might go off before
     * we get a chance to cancel it
     */
    long elapsedRT = alarmTime - System.currentTimeMillis();
    if (elapsedRT <= 0) {
        Log.v(TAG, "LocTrigService: negative elapsed realtime - " + "alarm not setting: " + trigId);
        return;
    }

    Log.v(TAG, "LocTrigService: Setting alarm for " + elapsedRT + " millis into the future");

    alarmMan.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + elapsedRT, pi);
}

From source file:org.ohmage.triggers.types.location.LocTrigService.java

private void setTriggerAlwaysAlarm(int trigId, String trigDesc) {

    cancelTriggerAlwaysAlarm(trigId);/* w w  w. j  ava 2s.com*/

    LocTrigDesc desc = new LocTrigDesc();
    if (!desc.loadString(trigDesc)) {
        return;
    }

    if (!desc.shouldTriggerAlways()) {
        return;
    }

    Log.i(DEBUG_TAG, "LocTrigService: Setting trigger always alarm(" + trigId + ", " + trigDesc + ")");

    Calendar target = Calendar.getInstance();
    target.set(Calendar.HOUR_OF_DAY, desc.getEndTime().getHour());
    target.set(Calendar.MINUTE, desc.getEndTime().getMinute());
    target.set(Calendar.SECOND, 0);

    LocationTrigger locTrig = new LocationTrigger();
    if (locTrig.hasTriggeredToday(this, trigId)) {
        target.add(Calendar.DAY_OF_YEAR, 1);
    } else if (System.currentTimeMillis() >= target.getTimeInMillis()) {
        target.add(Calendar.DAY_OF_YEAR, 1);
    }

    Intent i = createTriggerAlwaysAlarmIntent(trigId);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

    AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE);

    Log.i(DEBUG_TAG, "LocTrigService: Calculated target time: " + target.getTime().toString());

    long alarmTime = target.getTimeInMillis();

    /* Convert the alarm time to elapsed real time. 
     * If we dont do this, a time change in the system might
     * set off all the alarms and a trigger might go off before
     * we get a chance to cancel it
     */
    long elapsedRT = alarmTime - System.currentTimeMillis();
    if (elapsedRT <= 0) {
        Log.i(DEBUG_TAG, "LocTrigService: negative elapsed realtime - " + "alarm not setting: " + trigId);
        return;
    }

    Log.i(DEBUG_TAG, "LocTrigService: Setting alarm for " + elapsedRT + " millis into the future");

    alarmMan.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + elapsedRT, pi);
}

From source file:goo.TeaTimer.TimerActivity.java

/**
 * Starts the timer at the given time/*w  w  w. j a v  a2  s. c  o m*/
 * @param time with which to count down
 * @param service whether or not to start the service as well
 */
private void timerStart(int time, boolean service) {
    if (LOG)
        Log.v(TAG, "Starting the timer...");

    // Star external service
    enterState(RUNNING);

    if (service) {
        if (LOG)
            Log.v(TAG, "Starting the timer service ...");
        Intent intent = new Intent(getApplicationContext(), TimerReceiver.class);
        intent.putExtra("SetTime", mLastTime);
        mPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        mAlarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + time,
                mPendingIntent);
    }

    // Internal thread to properly update the GUI
    mTimer = new Timer();
    mTime = time;
    mTimer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            timerTic();
        }
    }, 0, TIMER_TIC);

    aquireWakeLock();
}

From source file:edu.missouri.bas.service.SensorService.java

public void startSound() {

    Intent scheduleTriggerSound = new Intent(SensorService.ACTION_TRIGGER_SOUND);
    Intent scheduleTriggerSound2 = new Intent(SensorService.ACTION_TRIGGER_SOUND2);
    triggerSound = PendingIntent.getBroadcast(serviceContext, 0, scheduleTriggerSound, 0);
    triggerSound2 = PendingIntent.getBroadcast(serviceContext, 0, scheduleTriggerSound2, 0);
    mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000, triggerSound);
    mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000 * 20,
            triggerSound2);/*  w ww  .j av  a 2  s  .c  om*/

}

From source file:org.telepatch.android.NotificationsController.java

private void scheduleNotificationRepeat() {
    try {//from ww  w  . j  a v  a 2 s. c  o m
        AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
        PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0,
                new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0);
        if (personal_count > 0) {
            alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60 * 60 * 1000,
                    pintent);
        } else {
            alarm.cancel(pintent);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:com.ubergeek42.WeechatAndroid.service.RelayServiceBackbone.java

@TargetApi(19)
void schedulePing(long triggerAt, Bundle extras) {
    Intent intent = new Intent(PingActionReceiver.PING_ACTION);
    intent.putExtras(extras);/* w  w w  .j  av  a2 s .c  o  m*/

    PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        alarmMgr.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAt, alarmIntent);
    } else {
        alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAt, alarmIntent);
    }
}

From source file:com.negaheno.android.NotificationsController.java

private void scheduleNotificationRepeat() {
    try {//  w w  w .  j a  v  a2  s  .  c om
        AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
        PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0,
                new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0);
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        int minutes = preferences.getInt("repeat_messages", 60);
        if (minutes > 0 && personal_count > 0) {
            alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000,
                    pintent);
        } else {
            alarm.cancel(pintent);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:org.sipdroid.sipua.ui.Receiver.java

static void pos_gps(boolean enable) {
    if (gps_sender == null) {
        Intent intent = new Intent(mContext, OneShotLocation.class);
        gps_sender = PendingIntent.getBroadcast(mContext, 0, intent, 0);
    }/*from   w w w.ja v  a  2  s . c o  m*/
    if (enable) {
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_UPDATES, 3000, gps_sender);
        am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 10 * 1000, gps_sender);
    } else {
        am.cancel(gps_sender);
        lm.removeUpdates(gps_sender);
    }
}

From source file:com.negaheno.android.NotificationsController.java

private void scheduleNotificationDelay(boolean onlineReason) {
    try {//from ww w . ja v a 2 s .c o m
        FileLog.e("tmessages", "delay notification start");
        AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
        PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0,
                new Intent(ApplicationLoader.applicationContext, NotificationDelay.class), 0);
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        if (onlineReason) {
            alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 3 * 1000, pintent);
        } else {
            alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 500, pintent);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}