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:net.kourlas.voipms_sms.receivers.SynchronizationIntervalReceiver.java

public static void setupSynchronizationInterval(Context applicationContext) {
    Preferences preferences = Preferences.getInstance(applicationContext);
    AlarmManager alarmManager = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(applicationContext, SynchronizationIntervalReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(applicationContext, 0, intent, 0);

    alarmManager.cancel(pendingIntent);/*www  .ja v a2 s. c o  m*/

    long syncInterval = preferences.getSyncInterval() * (24 * 60 * 60 * 1000);
    if (syncInterval != 0) {
        long nextSyncTime = preferences.getLastCompleteSyncTime() + syncInterval;

        long now = System.currentTimeMillis();
        if (nextSyncTime <= now) {
            Database.getInstance(applicationContext).synchronize(false, false, null);
            nextSyncTime = now + syncInterval;
        }

        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, nextSyncTime, syncInterval, pendingIntent);
    }
}

From source file:com.meiste.greg.ptw.RaceAlarm.java

@SuppressLint("NewApi")
public static void set(final Context context) {
    final Race race = Race.getNext(context, true, true);

    if (!alarm_set && (race != null)) {
        Util.log("Setting race alarm for race " + race.getId());

        final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        final Intent intent = new Intent(context, RaceAlarm.class);
        intent.putExtra(RACE_ID, race.getId());
        final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            am.setExact(AlarmManager.RTC_WAKEUP, race.getStartTimestamp(), pendingIntent);
        } else {/*from   w w w  .j  a v  a  2s  . c  o  m*/
            am.set(AlarmManager.RTC_WAKEUP, race.getStartTimestamp(), pendingIntent);
        }

        alarm_set = true;
    } else {
        Util.log("Not setting race alarm: alarm_set=" + alarm_set);
    }
}

From source file:mobile.tiis.appv2.postman.RoutineAlarmReceiver.java

/**
 * Sets a repeating alarm that runs once every 5 minutes When the
 * alarm fires, the appv2 broadcasts an Intent to this WakefulBroadcastReceiver.
 *
 * @param context//from  w  ww. j  a va 2 s . c o  m
 */
public static void setPostmanAlarm(Context context) {
    if (alarmMgr == null)
        alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, RoutineAlarmReceiver.class);
    intent.putExtra("setPostmanAlarm", true);
    alarmIntent = PendingIntent.getBroadcast(context, 111, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 30000,
            30000, alarmIntent);
}

From source file:Main.java

public static <T extends BroadcastReceiver> void scheduleUpdate(Context context, Class<T> clazz) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, clazz);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    Random random = new Random(System.currentTimeMillis());
    long offset = random.nextLong() % (12 * 60 * 60 * 1000);
    long interval = (24 * 60 * 60 * 1000) + offset;
    String prefKey = "pref_scheduled_monitor_config_update_" + clazz.getCanonicalName();
    long scheduledTime = preferences.getLong(prefKey, -1);

    if (scheduledTime == -1) {
        context.sendBroadcast(intent);//from www . jav a2  s . co  m
    }

    if (scheduledTime <= System.currentTimeMillis()) {
        context.sendBroadcast(intent);
        scheduledTime = System.currentTimeMillis() + interval;
        preferences.edit().putLong(prefKey, scheduledTime).commit();
        Log.w("PeriodicActionUtils",
                "Scheduling for all new time: " + scheduledTime + " (" + clazz.getSimpleName() + ")");
    } else {
        Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime + " ("
                + clazz.getSimpleName() + ")");
    }

    am.cancel(sender);
    am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender);

    Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime + " (" + clazz.getSimpleName() + ")");
}

From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java

public static void createAlarm(Context context, Schedule schedule) {
    Log.w("UTILS", "createAlarm() / Scheduled: " + schedule.getId());
    Intent alarmIntent = new Intent(context, Alarm.class);
    alarmIntent.putExtra(Alarm.PREF_ALARM_ID, schedule.getId());

    PendingIntent pi = PendingIntent.getBroadcast(context, SystemUtils.safeLongToInt(schedule.getId()),
            alarmIntent, 0);/*w ww.j  av  a 2 s .c  o  m*/

    AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmMgr.set(AlarmManager.RTC_WAKEUP, schedule.getDate(), pi);
}

From source file:dk.kk.cykelsuperstier.reminders.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    if (getAbortBroadcast()) {
        return;/*from w ww  .j av  a 2  s .  co m*/
    }
    int repetition = intent.getExtras().getInt("repetition");
    if (repetition >= 0) {
        // Find next alarm time.
        // If repetition is EVERY_DAY no need to set again, reminder was
        // initially set repetitive.+
        Calendar nextAlarmTime = AlarmUtils.calculateNextAlarmTime(repetition);
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent newIntent = new Intent(AlarmUtils.ALARM_ACTION);
        newIntent.putExtra("repetition", repetition);
        PendingIntent sender = PendingIntent.getBroadcast(context,
                CykelPlanenApplication.ALARM_REQUEST_CODE + 1, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        am.set(AlarmManager.RTC_WAKEUP, nextAlarmTime.getTimeInMillis(), sender);
    }

    createNotification(context, repetition);
}

From source file:com.spoiledmilk.cykelsuperstier.reminders.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    if (getAbortBroadcast()) {
        return;/*w  w w .  j  a  va2  s .com*/
    }
    int repetition = intent.getExtras().getInt("repetition");
    if (repetition >= 0) {
        // Find next alarm time.
        // If repetition is EVERY_DAY no need to set again, reminder was
        // initially set repetitive.+
        Calendar nextAlarmTime = AlarmUtils.calculateNextAlarmTime(repetition);
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent newIntent = new Intent(AlarmUtils.ALARM_ACTION);
        newIntent.putExtra("repetition", repetition);
        PendingIntent sender = PendingIntent.getBroadcast(context,
                CykelsuperstierApplication.ALARM_REQUEST_CODE + 1, newIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        am.set(AlarmManager.RTC_WAKEUP, nextAlarmTime.getTimeInMillis(), sender);
    }

    createNotification(context, repetition);
}

From source file:com.packpublishing.asynchronousandroid.chapter6.SMSDispatchActivity.java

void launchService(String phoneMumber, String text, long time) {

    Intent intent = new Intent(this, SMSDispatcherIntentService.class);
    intent.putExtra(SMSDispatcherIntentService.TO_KEY, phoneMumber);
    intent.putExtra(SMSDispatcherIntentService.TEXT_KEY, text);
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);

    PendingIntent service = PendingIntent.getService(getBaseContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    am.set(AlarmManager.RTC_WAKEUP, time, service);
}

From source file:com.meiste.greg.ptw.QuestionAlarm.java

@SuppressLint("NewApi")
public static void set(final Context context) {
    // Get next points race: allow in progress
    Race race = Race.getNext(context, false, true);
    if (race == null)
        return;/*  w w w .j ava  2  s.com*/

    // Check if user was already reminded of in progress race
    if (Util.getState(context).getInt(LAST_REMIND, -1) >= race.getId()) {
        // Get next points race: do not allow in progress
        race = Race.getNext(context, false, false);
        if (race == null)
            return;
    }

    if (!alarm_set) {
        Util.log("Setting question alarm for race " + race.getId());

        final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        final Intent intent = new Intent(context, QuestionAlarm.class);
        intent.putExtra(RACE_ID, race.getId());
        final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            am.setExact(AlarmManager.RTC_WAKEUP, race.getQuestionTimestamp(), pendingIntent);
        } else {
            am.set(AlarmManager.RTC_WAKEUP, race.getQuestionTimestamp(), pendingIntent);
        }

        alarm_set = true;
    } else {
        Util.log("Not setting question alarm: alarm_set=" + alarm_set);
    }
}

From source file:com.metinkale.prayerapp.vakit.AlarmReceiver.java

public static void silenter(Context c, long dur) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    boolean silent = "silent".equals(prefs.getString("silenterType", "silent"));
    AudioManager aum = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);
    int ringermode = aum.getRingerMode();
    if ((ringermode != AudioManager.RINGER_MODE_SILENT)
            && ((ringermode != AudioManager.RINGER_MODE_VIBRATE) || silent)) {
        AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);

        Intent i;/*from   w  w  w.  j  a  v a 2  s.  c o m*/
        if (ringermode == AudioManager.RINGER_MODE_VIBRATE) {
            i = new Intent(c, setVibrate.class);
        } else {
            i = new Intent(c, setNormal.class);
        }

        PendingIntent service = PendingIntent.getBroadcast(c, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1000 * 60 * dur), service);

        if (PermissionUtils.get(c).pNotPolicy)
            aum.setRingerMode(silent ? AudioManager.RINGER_MODE_SILENT : AudioManager.RINGER_MODE_VIBRATE);

    }
}