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:org.hansel.myAlert.ReminderService.java

@Override
public void onCreate() {
    super.onCreate();
    //obtenemos el "nmero de intentos"
    getApplicationContext().registerReceiver(alarmReceiver, new IntentFilter(CANCEL_ALARM_BROADCAST));
    int count = PreferenciasHancel.getReminderCount(getApplicationContext());
    count++;/*from w ww. j a  v  a2 s  .  c o m*/
    PreferenciasHancel.setReminderCount(getApplicationContext(), count);
    Log.v("Conteo: " + count);
    if (count >= 3) {
        //detenemos la alarma del servicio de recordatorios. y lanzamos el servicio de Tracking 
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        am.cancel(Util.getReminderPendingIntennt(getApplicationContext()));
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(NOTIFICATION_ID);
        Log.v("Servicio de Rastreo....");
        Util.inicarServicio(getApplicationContext());

        startService(new Intent(getApplicationContext(), SendPanicService.class));
        stopSelf();
    } else {
        //mandamos una alerta de notificacin
        showNotifciation();
        playSound();
        mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        Vibra();
        Handler han = new Handler();
        run = new Runnable() {

            @Override
            public void run() {
                cancelAlarm();
                stopSelf();
            }
        };
        han.postDelayed(run, 1000 * 10);

        //alarma para "regresar" en caso que el usuario no de "click" en la notificacin
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        long due = System.currentTimeMillis() + (60000 * 3); // 3 minutos
        Log.v("Scheduling next update at " + new Date(due));
        am.set(AlarmManager.RTC_WAKEUP, due, Util.getReminderPendingIntennt(getApplicationContext()));

    }

}

From source file:org.pixmob.freemobile.netstat.SyncServiceTesting.java

public static void schedule(Context context, boolean enabled) {
    final Context appContext = context.getApplicationContext();
    final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent syncIntent = PendingIntent.getService(appContext, 0,
            new Intent(appContext, SyncServiceTesting.class), PendingIntent.FLAG_CANCEL_CURRENT);
    am.cancel(syncIntent);//from w ww . j  a  v a2s.  co  m

    if (enabled) {
        // Set the sync period.
        long period = AlarmManager.INTERVAL_HOUR;
        final int syncErrors = context.getSharedPreferences(INTERNAL_SP_NAME, MODE_PRIVATE)
                .getInt(INTERNAL_SP_KEY_SYNC_ERRORS, 0);
        if (syncErrors != 0) {
            // When there was a sync error, the sync period is longer.
            period = AlarmManager.INTERVAL_HOUR * Math.min(syncErrors, MAX_SYNC_ERRORS);
        }

        // Add a random time to prevent concurrent requests for the server.
        final long fuzz = RANDOM.nextInt(1000 * 60 * 30);
        period += fuzz;

        if (DEBUG) {
            Log.d(TAG, "Scheduling synchronization: next in " + (period / 1000 / 60) + " minutes");
        }
        final long syncTime = System.currentTimeMillis() + period;
        am.set(AlarmManager.RTC_WAKEUP, syncTime, syncIntent);
    } else {
        if (DEBUG) {
            Log.d(TAG, "Synchronization schedule canceled");
        }
    }
}

From source file:am.roadpolice.roadpolice.alarm.AlarmReceiver.java

/**
 * This function creates a new Alarm by given alarm type. if not {@link AlarmType#NONE}
 * value was given as a type alarm will be called Daily, Weekly or Monthly staring from
 * time when this function was called. All alarms which were created before will be canceled.
 *
 * @param context Application context/*from w w w  . ja  va2s. c  o m*/
 * @param type Alarm Type, accepted values are
 *              {@link AlarmType#NONE} if need to cancel all alarms,
 *              {@link AlarmType#DAILY} alarm will called daily
 *              {@link AlarmType#WEEKLY} alarm will called weekly
 *              {@link AlarmType#MONTHLY} alarm will called monthly
 */
public static void createAlarm(final Context context, AlarmType type) {

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());

    switch (type) {
    case DAILY:
        calendar.add(Calendar.DATE, 1);
        break;

    case WEEKLY:
        calendar.add(Calendar.DATE, 7);
        break;

    case MONTHLY:
        calendar.add(Calendar.MONTH, 1);
        break;
    }

    // Create Alarm Manager Object.
    if (mAlarmManager == null)
        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    //
    Intent intent = new Intent(context, AlarmReceiver.class);
    if (mAlarmIntent == null)
        mAlarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    // Remove all previously created alarms, before creating new one.
    if (mAlarmManager != null) {
        mAlarmManager.cancel(mAlarmIntent);

        // By default Disable Boot Receiver.
        int componentEnabledState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
        // For enabling/disabling Boot Receiver.
        ComponentName receiver = new ComponentName(context, AlarmReceiver.class);
        PackageManager pm = context.getPackageManager();

        // Set new alarm if provided interval is not none.
        if (!AlarmType.NONE.equals(type)) {
            Logger.debug("AlarmReceiver", String
                    .format("----> Next Update Date: %1$tA %1$tb %1$td %1$tY at %1$tI:%1$tM %1$Tp", calendar));
            // Enables Boot Receiver.
            componentEnabledState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
            // Set repeating alarm.
            final long timeInMillis = calendar.getTimeInMillis();
            mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeInMillis, type.getValue(),
                    mAlarmIntent);

            // Stores next Alert Time.
            PreferenceUtils.storeDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, timeInMillis);

        } else {
            PreferenceUtils.storeDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, -1);
        }

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

From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java

protected boolean scheduleSingleNotification(AlarmManager am, JSONObject obj) {
    PendingIntent pendingIntent = createPendingIntentForSchedule(obj.optString("id"));
    long time = obj.optLong("timeMillisSince1970", -1);
    if (time < 0) {
        return false;
    }//  w  ww.  j a va 2  s  .  c om
    am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
    return true;
}

From source file:com.rozrost.www.smartlocationreminder.GeofenceTransitionsIntentService.java

private void AlarmService(String PrimaryKey) {
    Intent intent = new Intent("com.rozrost.www.alertscreen.Receiver");
    intent.putExtra("PrimaryKey", PrimaryKey);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 2, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, 0, pendingIntent);
}

From source file:org.zywx.wbpalmstar.platform.push.mqttpush.PushGetData2.java

private void startKeepAlives() {
    Intent i = new Intent();
    i.setClass(mCtx, PushService.class);
    i.setAction(CLIENT_ID + ".KEEP_ALIVE");
    PendingIntent pi = PendingIntent.getService(mCtx, 0, i, 0);
    AlarmManager alarmMgr = (AlarmManager) mCtx.getSystemService(Service.ALARM_SERVICE);
    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + KEEP_ALIVE_INTERVAL,
            KEEP_ALIVE_INTERVAL, pi);/*from   w ww. j  av a2s .co  m*/
}

From source file:com.footprint.cordova.plugin.localnotification.LocalNotification.java

/**
 * Set an alarm.// ww  w.  j  a  v a 2 s .  c o m
 *
 * @param options
 *            The options that can be specified per alarm.
 * @param doFireEvent
 *            If the onadd callback shall be called.
 */
public static void add(Options options, boolean doFireEvent) {
    long triggerTime = options.getDate();

    Intent intent = new Intent(context, Receiver.class).setAction("" + options.getId())
            .putExtra(Receiver.OPTIONS, options.getJSONObject().toString());

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

    if (doFireEvent) {
        fireEvent("add", options.getId(), options.getJSON());
    }

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

From source file:com.xperia64.cosi.CosiActivity.java

public void scheduleAlarm() {
    if (checkAlarm()) {
        return;//from   w  ww.j ava2s.  com
    }
    final int interval = 60 * 30;
    Intent alarmIntent = null;
    PendingIntent pendingIntent = null;
    AlarmManager alarmManager = null;

    // OnCreate()
    alarmIntent = new Intent(this, NagReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), NagReceiver.REQUEST_CODE,
            alarmIntent, 0);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (interval * 1000),
            pendingIntent);
}

From source file:com.brayanarias.alarmproject.receiver.AlarmReceiver.java

private static void setAlarm(Context context, Alarm alarm) {
    try {//  ww  w .  j a  va 2s . c om
        PendingIntent pendingIntent = createPendingIntent(context, alarm);
        AlarmManager alarmManager = getAlarmManager(context);
        Calendar actual = Calendar.getInstance();
        actual.set(Calendar.SECOND, 0);
        actual.set(Calendar.MILLISECOND, 0);
        Calendar calendar = (Calendar) actual.clone();
        int ampm = alarm.getAmPm().equals("AM") ? Calendar.AM : Calendar.PM;
        if (alarm.getHour() == 12) {
            calendar.set(Calendar.HOUR, 0);
        } else {
            calendar.set(Calendar.HOUR, alarm.getHour());
        }
        calendar.set(Calendar.AM_PM, ampm);
        calendar.set(Calendar.MINUTE, alarm.getMinute());
        int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
        if (actual.getTimeInMillis() >= calendar.getTimeInMillis()) {
            if (alarm.getDaysOfAlamr().equals("0000000")) {
                calendar.add(Calendar.DATE, 1);
            } else {
                calendar.add(Calendar.DATE, getDaysFromNextAlarm(alarm.getDaysOfAlamr()));
            }
        } else {
            if (!AlarmUtilities.isToday(alarm.getDaysOfAlamr(), day)) {
                calendar.add(Calendar.DATE, getDaysFromNextAlarm(alarm.getDaysOfAlamr()));
            }
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            AlarmManager.AlarmClockInfo clockInfo = new AlarmManager.AlarmClockInfo(calendar.getTimeInMillis(),
                    pendingIntent);
            alarmManager.setAlarmClock(clockInfo, pendingIntent);
        } else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
        } else {
            alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
        }

    } catch (Exception e) {
        Log.e(tag, e.getLocalizedMessage(), e);
    }
}

From source file:jieehd.villain.updater.VillainUpdater.java

public void setRepeatingAlarm() {
    AlarmManager am;//from   w w  w.j  a va  2  s  .co m
    am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(this, checkInBackground.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (3 * AlarmManager.INTERVAL_DAY),
            pendingIntent);
}