Example usage for android.app AlarmManager RTC

List of usage examples for android.app AlarmManager RTC

Introduction

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

Prototype

int RTC

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

Click Source Link

Document

Alarm time in System#currentTimeMillis System.currentTimeMillis() (wall clock time in UTC).

Usage

From source file:com.google.android.apps.santatracker.SantaNotificationBuilder.java

public static void ScheduleSantaNotification(Context c, long timestamp, int notificationType) {

    // Only schedule a notification if the time is in the future
    if (timestamp < System.currentTimeMillis()) {
        return;/*from  w w w .  j  a  va  2 s  . c  om*/
    }

    AlarmManager alarm = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);

    Intent i = new Intent(c, NotificationBroadcastReceiver.class);
    i.putExtra(NotificationConstants.KEY_NOTIFICATION_ID, NotificationConstants.NOTIFICATION_ID);

    // Type is "takeoff", "location", etc.
    i.putExtra(NotificationConstants.KEY_NOTIFICATION_TYPE, notificationType);

    // Generate unique pending intent
    PendingIntent pi = PendingIntent.getBroadcast(c, notificationType, i, 0);

    // Deliver next time the device is woken up
    alarm.set(AlarmManager.RTC, timestamp, pi);

}

From source file:org.ametro.app.ApplicationEx.java

public void changeAlarmReceiverState(boolean enabled) {
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent intent = new Intent(this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
    alarmManager.cancel(pendingIntent);/*from  w w w  .ja  v a 2  s.  c  om*/
    if (enabled) {
        long interval = (GlobalSettings.getUpdatePeriod(this) == 900) ? AlarmManager.INTERVAL_FIFTEEN_MINUTES
                : AlarmManager.INTERVAL_DAY;
        alarmManager.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + 1000 * 60 * 2, interval,
                pendingIntent);
    }
}

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

private static void updateAlarms(final Context ctx) {
    new Thread(new Runnable() {
        @Override//from  ww w .  j  ava 2s.com
        public void run() {
            Log.e(TAG, "update");
            alarmManager = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
            // Update the Notifications at midnight
            final Intent intent = new Intent(ctx, ReminderAlarm.class);
            intent.setAction(UPDATE_NOTIFICATION);
            final PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            final Calendar triggerCal = new GregorianCalendar();
            triggerCal.set(Calendar.HOUR_OF_DAY, 0);
            triggerCal.set(Calendar.MINUTE, 0);
            triggerCal.add(Calendar.DAY_OF_MONTH, 1);
            alarmManager.setRepeating(AlarmManager.RTC, triggerCal.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                    pendingIntent);
            // Alarms
            final List<Task> tasks = Task.getTasksWithReminders();
            final Calendar now = new GregorianCalendar();
            for (final Pair<Task, PendingIntent> p : activeAlarms) {
                final Task t = p.first;
                final Task newTask = Task.get(t.getId()).orNull();
                if ((newTask == null) || !newTask.getReminder().isPresent() || newTask.isDone()
                        || newTask.getReminder().get().after(new GregorianCalendar())) {
                    cancelAlarm(ctx, t, newTask, p, p.second);
                } else if (newTask.getReminder().isPresent()) {
                    if (newTask.getReminder().get().after(now) && !newTask.getRecurringReminder().isPresent()) {
                        closeNotificationFor(ctx, t.getId());
                        updateAlarm(ctx, newTask);
                    } else if (newTask.getReminder().get().after(now)
                            && newTask.getRecurringReminder().isPresent()
                            && (newTask.getReminder().get()
                                    .compareTo(newTask.getRecurringReminder().get()
                                            .addRecurring(newTask.getReminder()).orNull()) > 0)
                            && !now.after(newTask.getReminder())) {
                        updateAlarm(ctx, newTask);
                    } else if ((t.getRecurringReminderId() != newTask.getRecurringReminderId())
                            || t.getRecurringReminder().isPresent()) {
                        if (t.getRecurringReminder().isPresent()
                                && newTask.getRecurringReminder().isPresent()) {
                            if (!t.getRecurringReminder().get().equals(newTask.getRecurringReminder().get())) {
                                updateAlarm(ctx, newTask);
                                cancelAlarm(ctx, t, newTask, p, p.second);
                            }
                        } else if (t.getRecurringReminder().isPresent() != newTask.getRecurringReminder()
                                .isPresent()) {
                            updateAlarm(ctx, newTask);
                            cancelAlarm(ctx, t, newTask, p, p.second);
                        }
                    } else {
                        updateAlarm(ctx, newTask);
                    }
                }
            }
            for (final Task t : tasks) {
                try {
                    if (!isAlarm(t)) {
                        Log.d(TAG, "add: " + t.getName());
                        Log.i(TAG, "id " + t.getId());
                        final PendingIntent p = updateAlarm(ctx, t);
                        activeAlarms.add(new Pair<>(t, p));
                    }
                } catch (final NoSuchTaskException e) {
                    Log.wtf(TAG, "Task not found", e);
                }
            }
        }
    }).start();
}

From source file:at.diamonddogs.util.CacheManager.java

/**
 * Turn on scheduled cache cleaning (cache will be cleaned even if app is
 * not running)/*  ww w  . j a  v  a 2  s. c o  m*/
 *
 * @param context a {@link Context}
 */
public void enableScheduledCacheCleaner(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    // @formatter:off
    am.setInexactRepeating(AlarmManager.RTC, Utils.getScheduledDate(Calendar.SUNDAY, 3, 0, 0).getTimeInMillis(),
            7 * AlarmManager.INTERVAL_DAY, getAlarmIntent(context));
    // @formatter:on
    Log.i(TAG, "Cache cleaning alarm has been set.");
}

From source file:com.robsterthelobster.ucibustracker.ArrivalsFragment.java

private void updateRouteData() {
    Intent alarmIntent = new Intent(getActivity(), UciBusIntentService.AlarmReceiver.class);

    PendingIntent pi = PendingIntent.getBroadcast(getActivity(), 0, alarmIntent, 0);

    AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 0);
    long frequency = 60 * 1000; // one minute, which is the minimum

    am.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), frequency, pi);
}

From source file:com.jereksel.rommanager.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.

    switch (item.getItemId()) {
    case R.id.delete_xml:

        new Thread() {
            public void run() {

                runOnUiThread(new Runnable() {
                    @Override// ww w .j  a  v  a  2  s .  c o m
                    public void run() {
                        Dialog = ProgressDialog.show(context, "Downloading/Preparing Data..", "Please wait",
                                true, false);
                    }
                });

                DownloadXML array;

                array = new DownloadXML(context, true);
                (array).start();

                try {
                    array.join();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Dialog.dismiss();
                        Intent mStartActivity = new Intent(context, MainActivity.class);
                        int mPendingIntentId = 123456;
                        PendingIntent mPendingIntent = PendingIntent.getActivity(context, mPendingIntentId,
                                mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
                        AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
                        System.exit(0);

                    }
                });

            }
        }.start();
        break;

    case R.id.about_screen:
        Intent in = new Intent(context, AboutScreen.class);
        startActivity(in);
        break;

    case R.id.changelog_dialog:
        Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getString(R.string.AppChangelog));
        builder.setCancelable(true);
        AlertDialog dialog = builder.create();
        dialog.show();
        break;
    }

    return mDrawerToggle.onOptionsItemSelected(item);

}

From source file:ca.zadrox.dota2esportticker.service.UpdateMatchService.java

private void scheduleAutoUpdates() {

    if (!PrefUtils.shouldAutoUpdate(this)) {
        return;/*  www.j a va 2  s .c om*/
    }

    final long currentTime = TimeUtils.getUTCTime();

    final Intent updateMatchIntent = new Intent(UpdateMatchService.ACTION_AUTO_UPDATE_MATCHES, null, this,
            UpdateMatchService.class);

    final Intent updateResultIntent = new Intent(UpdateMatchService.ACTION_UPDATE_RESULTS, null, this,
            UpdateMatchService.class);

    final long matchUpdateTime = currentTime + (60000 * 60 * 12);
    final long resultUpdateTime = currentTime + (60000 * 60);

    PendingIntent umi = PendingIntent.getService(this.getApplicationContext(), 0, updateMatchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    PendingIntent uri = PendingIntent.getService(this.getApplicationContext(), 0, updateResultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);

    am.cancel(umi);
    am.cancel(uri);

    am.setInexactRepeating(AlarmManager.RTC, matchUpdateTime, AlarmManager.INTERVAL_HALF_DAY, umi);

    am.setInexactRepeating(AlarmManager.RTC, resultUpdateTime, AlarmManager.INTERVAL_HOUR, uri);
}

From source file:com.nextgis.maplibui.service.TrackerService.java

private void addSplitter() {
    // set midnight track splitter
    Calendar today = Calendar.getInstance();
    today.set(Calendar.HOUR, 0);//from www .  ja v a 2 s .  c o  m
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);
    today.add(Calendar.DATE, 1);
    mAlarmManager.set(AlarmManager.RTC, today.getTimeInMillis(), mSplitService);
}

From source file:gov.whitehouse.services.LiveService.java

private void scheduleNextUpdate() {
    Intent intent = new Intent(this, this.getClass());
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    long now = System.currentTimeMillis();
    int intervalSeconds = getResources().getInteger(R.integer.live_feed_update_interval_seconds);
    long intervalMillis = intervalSeconds * DateUtils.SECOND_IN_MILLIS;
    long nextUpdateTimeMillis = now + intervalMillis;

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent);
}

From source file:com.android.settings.cyanogenmod.LtoService.java

private PendingIntent scheduleNextDownload(long lastDownload) {
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(this, LtoService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    long nextLtoDownload = lastDownload + LongTermOrbits.getDownloadInterval();
    am.set(AlarmManager.RTC, nextLtoDownload, pi);
    return pi;/* w  ww. j  a  v  a  2 s.  c  om*/
}