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:se.hyperlab.tigcm.TiGCMModule.java

@Kroll.method
public void schedule(long time, HashMap data) {
    TiApplication app = TiApplication.getInstance();
    int ntfId = app.getAppProperties().getInt(PROPERTY_NOTIFICATION_COUNTER, 0);

    Log.d(TAG, "Scheduling notification " + ntfId + " at " + time);

    Intent intent = new Intent(app.getApplicationContext(), NotificationPublisher.class);
    intent.putExtra(PROPERTY_NOTIFICATION_DATA, data);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(app.getApplicationContext(), ntfId, intent,
            PendingIntent.FLAG_ONE_SHOT);

    AlarmManager alarmManager = (AlarmManager) app.getApplicationContext()
            .getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);

    app.getAppProperties().setInt(PROPERTY_NOTIFICATION_COUNTER, ntfId + 1);
}

From source file:at.jclehner.rxdroid.NotificationReceiver.java

private void scheduleNextBeginOrEndAlarm(DoseTimeInfo dtInfo, boolean scheduleEnd) {
    final int doseTime = scheduleEnd ? dtInfo.activeDoseTime() : dtInfo.nextDoseTime();
    final Calendar time = dtInfo.currentTime();
    final Date doseTimeDate = scheduleEnd ? dtInfo.activeDate() : dtInfo.nextDoseTimeDate();

    final Bundle alarmExtras = new Bundle();
    alarmExtras.putSerializable(EXTRA_DATE, doseTimeDate);
    alarmExtras.putInt(EXTRA_DOSE_TIME, doseTime);
    alarmExtras.putBoolean(EXTRA_IS_DOSE_TIME_END, scheduleEnd);
    alarmExtras.putBoolean(EXTRA_SILENT, false);

    long offset;/*from   www .j a  va  2 s. co m*/

    if (scheduleEnd)
        offset = Settings.getMillisUntilDoseTimeEnd(time, doseTime);
    else
        offset = Settings.getMillisUntilDoseTimeBegin(time, doseTime);

    long triggerAtMillis = time.getTimeInMillis() + offset;

    final long alarmRepeatMins = Settings.getStringAsInt(Settings.Keys.ALARM_REPEAT, 0);
    final long alarmRepeatMillis = alarmRepeatMins == -1 ? 10000 : alarmRepeatMins * 60000;

    if (alarmRepeatMillis > 0) {
        alarmExtras.putBoolean(EXTRA_FORCE_UPDATE, true);

        final long base = dtInfo.activeDate().getTime();
        int i = 0;

        while (base + (i * alarmRepeatMillis) < time.getTimeInMillis())
            ++i;

        // We must tell the receiver whether the alarm is an actual dose time's
        // end or begin, or merely a repetition.

        final long triggerAtMillisWithRepeatedAlarm = base + i * alarmRepeatMillis;
        if (triggerAtMillisWithRepeatedAlarm < triggerAtMillis) {
            triggerAtMillis = triggerAtMillisWithRepeatedAlarm;
            alarmExtras.putBoolean(EXTRA_IS_ALARM_REPETITION, true);
        }

        //triggerAtMillis = base + (i * alarmRepeatMillis);
    }

    final long triggerDiffFromNow = triggerAtMillis - System.currentTimeMillis();
    if (triggerDiffFromNow < 0) {
        if (triggerDiffFromNow < -50000)
            Log.w(TAG, "Alarm time is in the past by less than 5 seconds.");
        else {
            Log.w(TAG, "Alarm time is in the past. Ignoring...");
            return;
        }
    }

    if (alarmExtras.getBoolean(EXTRA_IS_ALARM_REPETITION))
        Log.i(TAG, "Scheduling next alarm for " + DateTime.toString(triggerAtMillis));
    else {
        Log.i(TAG, "Scheduling " + (scheduleEnd ? "end" : "begin") + " of doseTime " + doseTime + " on date "
                + DateTime.toDateString(doseTimeDate) + " for " + DateTime.toString(triggerAtMillis));
    }

    Log.i(TAG, "Alarm will go off in " + Util.millis(triggerDiffFromNow));

    mAlarmMgr.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, createOperation(alarmExtras));
}

From source file:com.home.pr.opendoor.MainActivity.java

public void schedulePeriodicUpdate() {
    /*final Handler handler = new Handler();
    handler.postDelayed(new Runnable(){//from w ww .  j av  a2s.  c  o m
    @Override
    public void run() {
        handler.postDelayed(this,10000);
        Intent intent = new Intent(getApplicationContext(), AdafruitDoorStatus.class);
        getApplicationContext().startService(intent);
    }
    },10000);*/
    Intent intent = new Intent(this, StatusReceiver.class);
    PendingIntent pIntent = PendingIntent.getBroadcast(this, StatusReceiver.REQUEST_CODE, intent, 0);
    long firstMillis = System.currentTimeMillis();
    AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstMillis, 10000, pIntent);
}

From source file:org.mozilla.gecko.updater.UpdateService.java

private void registerForUpdates(boolean isRetry) {
    Calendar lastAttempt = getLastAttemptDate();
    Calendar now = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    int interval = getUpdateInterval(isRetry);

    if (lastAttempt == null || (now.getTimeInMillis() - lastAttempt.getTimeInMillis()) > interval) {
        // We've either never attempted an update, or we are passed the desired
        // time. Start an update now.
        Log.i(LOGTAG, "no update has ever been attempted, checking now");
        startUpdate(0);/*from   w  w  w.j  a v  a2 s.com*/
        return;
    }

    AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    if (manager == null)
        return;

    PendingIntent pending = PendingIntent.getService(this, 0,
            new Intent(UpdateServiceHelper.ACTION_CHECK_FOR_UPDATE, null, this, UpdateService.class),
            PendingIntent.FLAG_UPDATE_CURRENT);
    manager.cancel(pending);

    lastAttempt.setTimeInMillis(lastAttempt.getTimeInMillis() + interval);
    Log.i(LOGTAG, "next update will be at: " + lastAttempt.getTime());

    manager.set(AlarmManager.RTC_WAKEUP, lastAttempt.getTimeInMillis(), pending);
}

From source file:com.QuarkLabs.BTCeClient.MainActivity.java

/**
 * Sets up alarm used for periodic check
 *
 * @param msecs Checking period//from w w w.j a  v a 2 s  .  c  om
 */
public void setRecurringAlarm(long msecs) {
    Intent downloader = new Intent(this, StartServiceReceiver.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pendingIntent = PendingIntent.getBroadcast(this, 0, downloader, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, msecs,
            pendingIntent);
    alarmSet = true;
}

From source file:com.glanznig.beepme.BeeperApp.java

public void setTimer() {
    if (isBeeperActive()) {
        Calendar alarmTime = Calendar.getInstance();
        Calendar alarmTimeUTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

        if (timerProfile == null) {
            setTimerProfile();/*w  ww  . ja v  a2 s .  c om*/
        }

        long timer = timerProfile.getTimer(this.getApplicationContext());
        alarmTime.add(Calendar.SECOND, (int) timer);
        //Log.i(TAG, "alarm in " + timer + " seconds.");
        alarmTimeUTC.add(Calendar.SECOND, (int) timer);
        getPreferences().setScheduledBeepId(new ScheduledBeepTable(this.getApplicationContext())
                .addScheduledBeep(alarmTime.getTimeInMillis(), getPreferences().getUptimeId()));

        Intent intent = new Intent(this, BeepActivity.class);
        PendingIntent alarmIntent = PendingIntent.getActivity(this, ALARM_INTENT_ID, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager manager = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
        manager.set(AlarmManager.RTC_WAKEUP, alarmTimeUTC.getTimeInMillis(), alarmIntent);
    }
}

From source file:com.remdo.app.MainActivity.java

/**
 * Anables geopositioning service with configured minutes span in Services database
 *//*from  ww w  .  ja  v  a 2s . com*/
private void enableGeopositioning() {
    mGeoInterval = dm.getServcieMinutes("Geo");
    long milisegundos = mGeoInterval * 60 * 1000;

    Intent intent = new Intent(this, GeopositioningService.class);
    pendingGeoIntent = PendingIntent.getService(this, 0, intent, 0);

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 10);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), milisegundos,
            pendingGeoIntent);

    Toast.makeText(this, getString(R.string.started_geo_service), Toast.LENGTH_LONG).show();
}

From source file:com.razza.apps.iosched.service.SessionAlarmService.java

public void scheduleFeedbackAlarm(final long sessionEnd, final long alarmOffset, final String sessionTitle) {
    // By default, feedback alarms fire 5 minutes before session end time. If alarm offset is
    // provided, alarm is set to go off that much time from now (useful for testing).
    long alarmTime;
    if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
        alarmTime = sessionEnd - MILLI_FIVE_MINUTES;
    } else {/*ww w.j  a  v a2 s .c  om*/
        alarmTime = UIUtils.getCurrentTime(this) + alarmOffset;
    }

    LogUtils.LOGD(TAG, "Scheduling session feedback alarm for session '" + sessionTitle + "'");
    LogUtils.LOGD(TAG, "  -> end time: " + sessionEnd + " = " + (new Date(sessionEnd)).toString());
    LogUtils.LOGD(TAG, "  -> alarm time: " + alarmTime + " = " + (new Date(alarmTime)).toString());

    final Intent feedbackIntent = new Intent(ACTION_NOTIFY_SESSION_FEEDBACK, null, this,
            SessionAlarmService.class);
    PendingIntent pi = PendingIntent.getService(this, 1, feedbackIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:com.google.samples.apps.iosched.service.SessionAlarmService.java

public void scheduleFeedbackAlarm(final long sessionEnd, final long alarmOffset, final String sessionTitle) {
    // By default, feedback alarms fire 5 minutes before session end time. If alarm offset is
    // provided, alarm is set to go off that much time from now (useful for testing).
    long alarmTime;
    if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
        alarmTime = sessionEnd - MILLI_FIVE_MINUTES;
    } else {/*from   www  .j a  v  a  2s  . c  o m*/
        alarmTime = UIUtils.getCurrentTime(this) + alarmOffset;
    }

    LOGD(TAG, "Scheduling session feedback alarm for session '" + sessionTitle + "'");
    LOGD(TAG, "  -> end time: " + sessionEnd + " = " + (new Date(sessionEnd)).toString());
    LOGD(TAG, "  -> alarm time: " + alarmTime + " = " + (new Date(alarmTime)).toString());

    final Intent feedbackIntent = new Intent(ACTION_NOTIFY_SESSION_FEEDBACK, null, this,
            SessionAlarmService.class);
    PendingIntent pi = PendingIntent.getService(this, 1, feedbackIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:com.medicohealthcare.service.AlarmServer.java

public void setAlarm(Calendar calendar) {
    AlarmManager am = (AlarmManager) HomeActivity.getParentAtivity()
            .getSystemService(HomeActivity.getParentAtivity().getApplicationContext().ALARM_SERVICE);
    Intent intent = new Intent(HomeActivity.getParentAtivity(), AlarmService.class);
    long trigerTime = calendar.getTimeInMillis();
    System.out.println("trigerTime = " + trigerTime);
    System.out.println("trigerTime current = " + Calendar.getInstance().getTimeInMillis());

    PendingIntent pendingIntent = PendingIntent.getBroadcast(HomeActivity.getParentAtivity(), (int) trigerTime,
            intent, PendingIntent.FLAG_ONE_SHOT);
    am.set(AlarmManager.RTC_WAKEUP, trigerTime, pendingIntent);
}