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:at.florian_lentsch.expirysync.NotifyChecker.java

/**
 * Sets the alarm that checks for products soon to expire (or already have
 * expired)// w  w  w.  jav a 2s .c o  m
 * 
 * @param context
 */
protected static void setAlarm(Context context) {
    Context appContext = context.getApplicationContext();
    Intent receiverIntent = new Intent(appContext, NotifyChecker.class);

    // Fetch info about when the alarm is to sound each day from the shared
    // preferences:
    long firstStartMillis = getFirstStartMillis(appContext);
    if (firstStartMillis < 0) {
        Log.i("Alarm", "Alert time not configured - not setting alarm");
        return;
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(firstStartMillis);
    // Log.i("Alarm", "Setting alarm: " + firstStartMillis + ", " + (new
    // SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",
    // Locale.US)).format(firstStartMillis));

    // Set the alarm:
    PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, 0, receiverIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, firstStartMillis, AlarmManager.INTERVAL_DAY, alarmIntent);
}

From source file:com.abid_mujtaba.bitcoin.tracker.services.FetchPriceService.java

public static void start(Context context) // Method used to start service via AlarmManager
{
    Intent intent = new Intent(context, FetchPriceService.class); // Intent to launch service
    PendingIntent alarmIntent = PendingIntent.getService(context, 0, intent, 0); // PendingIntent required by AlarmManager. This gives the AlarmManager permission to launch this Intent as if it were being launched by this application

    AlarmManager amgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    amgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), INTERVAL, alarmIntent);
}

From source file:com.cryart.sabbathschool.util.SSNotification.java

public static void setRepeatingNotification(Context context) {
    AlarmManager _SSAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent _SSNotificationIntent = new Intent(context, SSBroadcastReceiver.class);
    PendingIntent _SSAlarmIntent = PendingIntent.getBroadcast(context, 0, _SSNotificationIntent, 0);

    Calendar _SSNotificationTime = Calendar.getInstance();

    SharedPreferences ssPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String ss_settings_notification_time = ssPreferences.getString(
            SSConstants.SS_SETTINGS_NOTIFICATION_TIME_KEY,
            SSConstants.SS_SETTINGS_NOTIFICATION_TIME_DEFAULT_VALUE);

    _SSNotificationTime.set(Calendar.HOUR_OF_DAY, SSHelper.parseHourFromString(ss_settings_notification_time,
            SSConstants.SS_NOTIFICATION_TIME_SETTINGS_FORMAT));
    _SSNotificationTime.set(Calendar.MINUTE, SSHelper.parseMinuteFromString(ss_settings_notification_time,
            SSConstants.SS_NOTIFICATION_TIME_SETTINGS_FORMAT));
    _SSNotificationTime.set(Calendar.SECOND, 0);

    _SSAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, _SSNotificationTime.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, _SSAlarmIntent);
}

From source file:nkarasch.repeatingreminder.scheduling.AlertBroadcastReceiver.java

/**
 * Schedules the next firing of this BroadcastReceiver based on the data in the Alert and fires the
 * Alert if appropriate//  w w w  .j  a  v a2s . co m
 */
@Override
public void onReceive(Context context, Intent intent) {

    Alert alert = intent.getParcelableExtra("alert");
    boolean initial = intent.getBooleanExtra("initial", false);

    intent.putExtra("initial", false);
    Calendar nextTime = getNextTime(Calendar.getInstance(), alert);
    if (nextTime != null) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        PendingIntent sender = PendingIntent.getBroadcast(context, alert.getId(), intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        alarmManager.set(AlarmManager.RTC_WAKEUP, nextTime.getTimeInMillis(), sender);
    }

    if (initial) {
        return;
    }

    Calendar calendar = Calendar.getInstance();
    if (!alert.isSchedule()) {
        fireNotification(context, alert);
    } else {
        if (isLegalDay(calendar, alert) && isLegalTime(calendar, alert) == DAY_POSITION.BETWEEN) {
            fireNotification(context, alert);
        }
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver.java

public AlarmReceiver() {
    Context context = GBApplication.getContext();
    Intent intent = new Intent("DAILY_ALARM");
    intent.setPackage(BuildConfig.APPLICATION_ID);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, new Intent("DAILY_ALARM"), 0);
    AlarmManager am = (AlarmManager) (context.getSystemService(Context.ALARM_SERVICE));

    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 10000,
            AlarmManager.INTERVAL_DAY, pendingIntent);
}

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

/**
 * This part starts the service that checks every 10 minutes for changes to child data
 *
 * @param context/*www.j  av  a2 s  .c o m*/
 */
public static void setAlarmCheckForChangesInChild(Context context) {
    if (alarmMgr == null)
        alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent childChanges = new Intent(context, RoutineAlarmReceiver.class);
    childChanges.putExtra("childChanges", true);
    checkForChangesInChildPI = PendingIntent.getBroadcast(context, 222, childChanges,
            PendingIntent.FLAG_UPDATE_CURRENT); //
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            Calendar.getInstance().getTimeInMillis() + (5 * 60000), (5 * 60000), checkForChangesInChildPI);
}

From source file:com.devnoobs.bmr.Powiadomienia.java

public void setAlarm(int h, int m) {
    Calendar calendar = przygotujCzas(h, m);

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

    Intent i = new Intent(S);
    PendingIntent pi = PendingIntent.getBroadcast(c, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    IntentFilter intentFilter = new IntentFilter(S);
    Powiadomienia p = new Powiadomienia();
    c.registerReceiver(p, intentFilter);

    am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60 * 10, pi); // Millisec * Sec * Min
    //am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), AlarmManager.INTERVAL_DAY, pi); //   
    showToast("Powiadomienie wlaczone");
}

From source file:org.isoron.uhabits.helpers.ReminderHelper.java

public static void createReminderAlarm(Context context, Habit habit, @Nullable Long reminderTime) {
    if (!habit.hasReminder())
        return;//ww  w.  j a  v a2 s.c o  m

    if (reminderTime == null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        //noinspection ConstantConditions
        calendar.set(Calendar.HOUR_OF_DAY, habit.reminderHour);
        //noinspection ConstantConditions
        calendar.set(Calendar.MINUTE, habit.reminderMin);
        calendar.set(Calendar.SECOND, 0);

        reminderTime = calendar.getTimeInMillis();

        if (System.currentTimeMillis() > reminderTime)
            reminderTime += AlarmManager.INTERVAL_DAY;
    }

    long timestamp = DateHelper.getStartOfDay(DateHelper.toLocalTime(reminderTime));

    Uri uri = habit.getUri();

    Intent alarmIntent = new Intent(context, HabitBroadcastReceiver.class);
    alarmIntent.setAction(HabitBroadcastReceiver.ACTION_SHOW_REMINDER);
    alarmIntent.setData(uri);
    alarmIntent.putExtra("timestamp", timestamp);
    alarmIntent.putExtra("reminderTime", reminderTime);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
            ((int) (habit.getId() % Integer.MAX_VALUE)) + 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    if (Build.VERSION.SDK_INT >= 23)
        manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
    else if (Build.VERSION.SDK_INT >= 19)
        manager.setExact(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
    else
        manager.set(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);

    String name = habit.name.substring(0, Math.min(3, habit.name.length()));
    Log.d("ReminderHelper", String.format("Setting alarm (%s): %s",
            DateFormat.getDateTimeInstance().format(new Date(reminderTime)), name));
}

From source file:mchs.neverforget.services.NotificationIntentService.java

public static void startCustomRecurrentNotificationAlarm(Context context, int customId) {
    //Toast.makeText(context, "startCustomRecurrentNotificationAlarm"+customId, Toast.LENGTH_SHORT).show();
    Intent intent = new Intent(context, NotificationIntentService.class);
    if (customId == 1) {
        intent.setAction(ACTION_NOTIFY_CUSTOM1);
    } else if (customId == 2) {
        intent.setAction(ACTION_NOTIFY_CUSTOM2);
    } else if (customId == 3) {
        intent.setAction(ACTION_NOTIFY_CUSTOM3);
    }/*from w w w. j a  v  a 2 s. c  om*/

    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);

    String[] hourOfDay = PreferenceManager.getDefaultSharedPreferences(context)
            .getString("notification_time_picker" + customId, "12:00").split(":");
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hourOfDay[0]));
    calendar.set(Calendar.MINUTE, Integer.parseInt(hourOfDay[1]));

    if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1);
    }
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, pendingIntent);

}

From source file:org.dodgybits.shuffle.android.server.sync.SyncSchedulingService.java

@Override
protected void onHandleIntent(Intent intent) {
    SyncState state = SyncState.restore(this);
    state.process(this, intent.getExtras());

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent syncIntent = new Intent(this, SyncReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, syncIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.set(AlarmManager.RTC_WAKEUP, state.nextScheduledSync, pendingIntent);

    // Release the wake lock provided by the WakefulBroadcastReceiver
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}