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:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

public static long setUpdateAlarm(Context context, boolean initial) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    Intent alarmintent = new Intent(context, AlarmReceiver.class);
    alarmintent.setAction(AlarmReceiver.ALARM_UPDATE);

    PendingIntent pendingintent = PendingIntent.getBroadcast(context, 0, alarmintent, 0);

    MyApp.LogDebug(LOG_TAG, "set update alarm");
    long next_fetch;
    long interval;
    Time t = new Time();
    t.setToNow();/*from w  w w. jav  a 2 s .co m*/
    long now = t.toMillis(true);

    if ((now >= MyApp.first_day_start) && (now < MyApp.last_day_end)) {
        interval = 2 * AlarmManager.INTERVAL_HOUR;
        next_fetch = now + interval;
    } else if (now >= MyApp.last_day_end) {
        MyApp.LogDebug(LOG_TAG, "cancel alarm post congress");
        alarmManager.cancel(pendingintent);
        return 0;
    } else {
        interval = AlarmManager.INTERVAL_DAY;
        next_fetch = now + interval;
    }

    if ((now < MyApp.first_day_start) && ((now + AlarmManager.INTERVAL_DAY) >= MyApp.first_day_start)) {
        next_fetch = MyApp.first_day_start;
        interval = 2 * AlarmManager.INTERVAL_HOUR;
        if (!initial) {
            MyApp.LogDebug(LOG_TAG, "update alarm to interval " + interval + ", next in " + (next_fetch - now));
            alarmManager.cancel(pendingintent);
            alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent);
        }
    }

    if (initial) {
        MyApp.LogDebug(LOG_TAG,
                "set initial alarm to interval " + interval + ", next in " + (next_fetch - now));
        alarmManager.cancel(pendingintent);
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent);
    }

    return interval;
}

From source file:support.plus.reportit.SettingsActivity.java

public void scheduleNotification(Notification notification, int hour, int minute) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);

    Intent notificationIntent = new Intent(this, AlarmReceiver.class);
    notificationIntent.putExtra(AlarmReceiver.NOTIFICATION_ID, 1);
    notificationIntent.putExtra(AlarmReceiver.NOTIFICATION, notification);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            pendingIntent);//  www . j  ava  2  s  .c  o  m

}

From source file:de.domjos.schooltools.activities.MainActivity.java

private void initServices() {
    try {//from w w w.j a  v  a 2s .co  m
        if (MainActivity.globals.getUserSettings().isNotificationsShown()) {
            // init Memory Service
            Intent intent = new Intent(this.getApplicationContext(), MemoryService.class);
            PendingIntent pendingIntent1 = PendingIntent.getService(this.getApplicationContext(), 0, intent, 0);

            // init frequently
            AlarmManager alarmManager1 = (AlarmManager) this.getApplicationContext()
                    .getSystemService(Context.ALARM_SERVICE);
            long frequency = 8 * 60 * 60 * 1000;
            assert alarmManager1 != null;
            alarmManager1.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis(),
                    frequency, pendingIntent1);
        }
    } catch (Exception ex) {
        Helper.printException(this.getApplicationContext(), ex);
    }
}

From source file:com.tvs.signaltracker.MainScreen.java

@Override
protected void onResume() {
    super.onResume();
    CleanUp();/*from  ww w. jav a2s. c  o  m*/
    try {
        if (STService.Opened == false) {
            Intent myIntent = new Intent(MainScreen.this, STService.class);
            PendingIntent pendingIntent = PendingIntent.getService(MainScreen.this, 0, myIntent, 0);
            AlarmManager alarmManager = (AlarmManager) MainScreen.this.getSystemService(Context.ALARM_SERVICE);
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.add(Calendar.SECOND, 1);
            alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
        }
    } catch (Exception e) {
        Log.e("SignalTracker::onResume(MainScreen)", "Erro ao iniciar servio: " + e.getMessage());
    }
    if (!CommonHandler.ServiceRunning)
        CommonHandler.LoadLists();
    setUpMap();
    InitUp();
}

From source file:com.mobiperf.MeasurementScheduler.java

private void handleMeasurement() {
    if (!userConsented()) {
        Logger.i("Skipping measurement - User has not consented");
        return;//from  w  w  w .  jav a2s . c  o  m
    }

    try {
        MeasurementTask task = taskQueue.peek();
        // Process the head of the queue.
        if (task != null && task.timeFromExecution() <= 0) {
            taskQueue.poll();
            Future<MeasurementResult> future;
            Logger.i("Processing task " + task.toString());
            // Run the head task using the executor
            if (task.getDescription().priority == MeasurementTask.USER_PRIORITY) {
                sendStringMsg("Scheduling user task:\n" + task);
                // User task can override the power policy. So a different task wrapper is used.
                future = measurementExecutor.submit(new UserMeasurementTask(task));
            } else {
                sendStringMsg("Scheduling task:\n" + task);
                future = measurementExecutor.submit(new PowerAwareTask(task, resourceCapManager, this));
            }
            synchronized (pendingTasks) {
                pendingTasks.put(task, future);
            }

            MeasurementDesc desc = task.getDescription();

            long newStartTime = desc.startTime.getTime() + (long) desc.intervalSec * 1000;

            // Add a clone of the task if it's still valid.
            if (newStartTime < desc.endTime.getTime()
                    && (desc.count == MeasurementTask.INFINITE_COUNT || desc.count > 1)) {
                MeasurementTask newTask = task.clone();
                if (desc.count != MeasurementTask.INFINITE_COUNT) {
                    newTask.getDescription().count--;
                }
                newTask.getDescription().startTime.setTime(newStartTime);
                submitTask(newTask);
            }
        }
        // Schedule the next measurement in the taskQueue
        task = taskQueue.peek();
        if (task != null) {
            long timeFromExecution = Math.max(task.timeFromExecution(),
                    Config.MIN_TIME_BETWEEN_MEASUREMENT_ALARM_MSEC);
            measurementIntentSender = PendingIntent.getBroadcast(this, 0,
                    new UpdateIntent("", UpdateIntent.MEASUREMENT_ACTION), PendingIntent.FLAG_CANCEL_CURRENT);
            alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeFromExecution,
                    measurementIntentSender);
        }
    } catch (IllegalArgumentException e) {
        // Task creation in clone can create this exception
        Logger.e("Exception when cloning task");
        sendStringMsg("Exception when cloning task: " + e);
    } catch (Exception e) {
        // We don't want any unexpected exception to crash the process
        Logger.e("Exception when handling measurements", e);
        sendStringMsg("Exception running task: " + e);
    }
    persistState();
}

From source file:de.schildbach.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    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/*from   ww w.  jav a  2 s .  c o  m*/
        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:com.dudu.aios.ui.activity.MainRecordActivity.java

private void setWeatherAlarm() {
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(this, WeatherAlarmReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, 0);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 20);
    mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 30 * 60 * 1000, pi);
}

From source file:com.gpsmobitrack.gpstracker.MenuItems.SettingsPage.java

/**
 * Start the alarm service /*from   w w  w. ja  va 2 s. c  o m*/
 * @param pos
 */
private void startAlarmService(int pos) {
    editor.putLong(AppConstants.FREQ_UPDATE_PREF, updateDurationValue[pos]);
    editor.commit();
    int updateTimeint = updateDurationValue[pos];
    AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
    Calendar cal = Calendar.getInstance();
    Intent intent2 = new Intent(getActivity(), BackgroundService.class);
    PendingIntent pintent = PendingIntent.getService(getActivity(), 0, intent2, 0);
    if (PendingIntent.getService(getActivity(), 0, intent2, PendingIntent.FLAG_NO_CREATE) != null) {
        alarm.cancel(pintent);
    }
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), (updateTimeint * 1000 * 60), pintent);
}

From source file:de.langerhans.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(@Nonnull final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    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/*  www  .  jav  a  2  s  .c  om*/
        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 Intent startIntent = new Intent(context, AutosyncReceiver.class);
    startIntent.setAction("de.langerhans.wallet.AUTOSYNC_ACTION");
    final PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, startIntent, 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:biz.wiz.android.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(@Nonnull final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    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// ww w.j  a va  2 s.  c  o  m
        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);
}