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:de.appplant.cordova.plugin.notification.Notification.java

/**
 * Schedule the local notification./*from  w ww  .jav a 2  s  . c om*/
 */
public void schedule() {
    long triggerTime = getNextTriggerTime();

    persist();

    // Intent gets called when the Notification gets fired
    Intent intent = new Intent(context, receiver).setAction(options.getId()).putExtra(Options.EXTRA,
            options.toString());

    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    getAlarmMgr().set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
}

From source file:co.carlosandresjimenez.android.gotit.notification.AlarmReceiver.java

/**
 * Sets a repeating alarm that runs once a day at approximately 8:30 a.m. When the
 * alarm fires, the app broadcasts an Intent to this WakefulBroadcastReceiver.
 *
 * @param context//from   ww w  .j av a 2  s.  com
 */
public void setAlarm(Context context) {

    // If the alarm has been set, cancel it.
    if (alarmMgr != null) {
        alarmIntent.cancel();
        alarmMgr.cancel(alarmIntent);
    }

    alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReceiver.class);
    alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

    int userFrequencySetting = Utility.getNotificationFrequency(context);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.HOUR, userFrequencySetting);

    // Set the alarm to fire in X hours according to the device's
    // clock and user settings, and to repeat according to user settings
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            userFrequencySetting * ONE_HOUR_MILLISECONDS, alarmIntent);

    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();

    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:org.hansel.myAlert.Rastreo.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {

        /*/*from   ww  w. ja v  a 2 s.  c  o m*/
        //cancelamos la alarma anterios en caso que se modificque
        alarmManager.cancel(Util.getServicePendingIntent(getActivity()));
        //obtenemos data para poder iniciar el rastreo:
        trackDate = (TrackDate) data.getExtras().get(TrackDialog.TRACK_EXTRA);
        //mostramos Botones De info
        setAlarm(trackDate.getEndTimeTrack());
        showCurrentTrackInfo(true);
        txtCurrentTrackInfo.setText(Util.getSimpleDateFormatTrack(trackDate.getStartDateTrack()) );
        //alarma para iniciar el servicio de "recordatorio"
         alarmManager.set(AlarmManager.RTC_WAKEUP, trackDate.getStartTimeTrack().getTimeInMillis(), Util.getServicePendingIntent(getActivity()));
         */
        cancelAlarms();
        PreferenciasHancel.setReminderCount(getActivity(), 0);
        trackDate = (TrackDate) data.getExtras().get(TrackDialog.TRACK_EXTRA);
        alarmManager.set(AlarmManager.RTC_WAKEUP, trackDate.getStartTimeTrack().getTimeInMillis(),
                Util.getReminderPendingIntennt(getActivity()));
        Log.v("Finalizando en: " + new Date(trackDate.getEndTimeTrack().getTimeInMillis()));
        alarmManager.set(AlarmManager.RTC_WAKEUP, trackDate.getEndTimeTrack().getTimeInMillis(),
                Util.getStopSchedulePendingIntentWithExtra(getActivity()));
        //guardamos inicio de alarma
        PreferenciasHancel.setAlarmStartDate(getActivity(), trackDate.getEndTimeTrack().getTimeInMillis());
        showCurrentTrackInfo(true);
        txtCurrentTrackInfo.setText(Util.getSimpleDateFormatTrack(trackDate.getStartTimeTrack()));

    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }

}

From source file:com.commontime.plugin.notification.notification.NotificationWrapper.java

/**
 * Schedule the local notification.//w w w .ja v a 2  s . c  om
 */
public void schedule() {
    long triggerTime = options.getTriggerTime();

    persist();

    // Intent gets called when the NotificationWrapper gets fired
    Intent intent = new Intent(context, receiver).setAction(options.getIdStr()).putExtra(Options.EXTRA,
            options.toString());

    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    if (isRepeating()) {
        getAlarmMgr().setRepeating(AlarmManager.RTC_WAKEUP, triggerTime, options.getRepeatInterval(), pi);
    } else {
        getAlarmMgr().set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
    }
}

From source file:org.onebusaway.android.directions.realtime.RealtimeService.java

private boolean possibleReschedule(Bundle bundle) {

    // Delay if this trip doesn't start for at least an hour
    Date start = new TripRequestBuilder(bundle).getDateTime();
    Date queryStart = new Date(start.getTime() - OTPConstants.REALTIME_SERVICE_QUERY_WINDOW);
    boolean reschedule = new Date().before(queryStart);

    if (reschedule) {
        Log.d(TAG, "Start service at " + queryStart);
        Intent future = new Intent(OTPConstants.INTENT_START_CHECKS);
        future.putExtras(bundle);/*from   ww  w  .  java 2s  .  c  o  m*/

        PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, future,
                PendingIntent.FLAG_CANCEL_CURRENT);
        getAlarmManager().set(AlarmManager.RTC_WAKEUP, queryStart.getTime(), pendingIntent);
    }

    return reschedule;
}

From source file:org.wso2.iot.agent.services.kiosk.KioskAlarmReceiver.java

/**
 * Generic function to generate alarm to both lock and unlock scenarios.
 * @param context Context of the application.
 * @param enableLock Set whether its a lock alarm or unlock alarm.
 * @param isInitialRun Set if its the initial alarm or not.
 *//*w  ww.  java 2 s .  c  o m*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void buildAlarm(Context context, boolean enableLock, boolean isInitialRun) {
    AlarmManager alarmManager;
    PendingIntent pendingIntent;
    Calendar calendar;
    int currentTime;
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (Preference.getBoolean(context, Constants.PreferenceCOSUProfile.ENABLE_LOCKDOWN)) {
        int freezeTime = Preference.getInt(context, Constants.PreferenceCOSUProfile.FREEZE_TIME);
        int releaseTime = Preference.getInt(context, Constants.PreferenceCOSUProfile.RELEASE_TIME);

        Intent receiverIntent = new Intent(context, KioskAlarmReceiver.class);
        receiverIntent.putExtra(Constants.Operation.ENABLE_LOCK, enableLock);

        if (!enableLock) {
            /* if releaseTime is after freezeTime, then needs to set unlock alarm in next day since
             device operation time extends to next day as well. */
            calendar = getCalendar(releaseTime, freezeTime > releaseTime);
        } else if (isInitialRun) {
            currentTime = getCurrentTimeInMinutes();
            /* if currentTime is larger than freezeTime, that means freeze time of current day is
            already passed. Therefore need to set alarm in next day. */
            calendar = getCalendar(freezeTime, currentTime > freezeTime);
        } else {
            /* if releaseTime is larger than freezeTime, that means the next freezeTime comes in
            next day. Therefore need to set alarm in next day. */
            calendar = getCalendar(freezeTime, releaseTime > freezeTime);
        }
        pendingIntent = PendingIntent.getBroadcast(context, 55, receiverIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
        Log.d(TAG, "Build alarm to restrict device to " + freezeTime + ":" + releaseTime);
    }
}

From source file:com.battlelancer.seriesguide.util.Utils.java

/**
 * Run the notification service delayed by a minute to display and (re)schedule upcoming episode
 * alarms.//from  w  w w .j  av a  2 s . c  o  m
 */
public static void runNotificationServiceDelayed(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, OnAlarmReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
    am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1 * DateUtils.MINUTE_IN_MILLIS, pi);
}

From source file:com.example.android.wearable.timer.SetTimerActivity.java

private void registerWithAlarmManager(long duration) {
    // Get the alarm manager.
    AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    // Create intent that gets fired when timer expires.
    Intent intent = new Intent(Constants.ACTION_SHOW_ALARM, null, this, TimerNotificationService.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Calculate the time when it expires.
    long wakeupTime = System.currentTimeMillis() + duration;

    // Schedule an alarm.
    alarm.setExact(AlarmManager.RTC_WAKEUP, wakeupTime, pendingIntent);
}

From source file:com.ota.updates.utils.Utils.java

public static void scheduleNotification(Context context, boolean cancel) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AppReceiver.class);
    intent.setAction(START_UPDATE_CHECK);
    int intentId = 1673;
    int intentFlag = PendingIntent.FLAG_UPDATE_CURRENT;

    if (cancel) {
        if (alarmManager != null) {
            if (DEBUGGING)
                Log.d(TAG, "Cancelling alarm");
            alarmManager.cancel(PendingIntent.getBroadcast(context, intentId, intent, intentFlag));
        }//from w  w w .j  ava 2s .  co m
    } else {
        int requestedInterval;

        if (DEBUG_NOTIFICATIONS) {
            requestedInterval = 30000;
        } else {
            requestedInterval = Preferences.getBackgroundFrequency(context);
        }

        if (DEBUGGING)
            Log.d(TAG, "Setting alarm for " + requestedInterval + " seconds");
        Calendar calendar = Calendar.getInstance();
        long time = calendar.getTimeInMillis() + requestedInterval * 1000;
        alarmManager.set(AlarmManager.RTC_WAKEUP, time,
                PendingIntent.getBroadcast(context, intentId, intent, intentFlag));
    }
}

From source file:at.andreasrohner.spartantimelapserec.BackgroundService.java

@SuppressWarnings("deprecation")
@Override//from  ww w  .jav  a2 s .co  m
public void onCreate() {
    created = true;

    settings = new RecSettings();
    settings.load(getApplicationContext(),
            PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));

    createNotification(NOTIFICATION_ID);

    if (settings.isSchedRecEnabled() && settings.getSchedRecTime() > System.currentTimeMillis() + 10000) {
        AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplicationContext(), ScheduleReceiver.class);
        PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);

        alarmMgr.set(AlarmManager.RTC_WAKEUP, settings.getSchedRecTime(), alarmIntent);

        stopSelf();
        return;
    }

    // Create new SurfaceView, set its size to 1x1, move
    // it to the top left corner and set this service as a callback
    WindowManager winMgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    surfaceView = new SurfaceView(this);
    // deprecated setting, but required on Android versions prior to 3.0
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    surfaceView.getHolder().addCallback(this);

    LayoutParams layoutParams = new WindowManager.LayoutParams(1, 1,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
            PixelFormat.TRANSLUCENT);
    layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
    winMgr.addView(surfaceView, layoutParams);

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    wakeLock.setReferenceCounted(false);
    wakeLock.acquire();
}