Example usage for android.app AlarmManager ELAPSED_REALTIME_WAKEUP

List of usage examples for android.app AlarmManager ELAPSED_REALTIME_WAKEUP

Introduction

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

Prototype

int ELAPSED_REALTIME_WAKEUP

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

Click Source Link

Document

Alarm time in android.os.SystemClock#elapsedRealtime SystemClock.elapsedRealtime() (time since boot, including sleep), which will wake up the device when it goes off.

Usage

From source file:Main.java

private static void schedulePendingIntent(Context context, PendingIntent pendingIntent, long frequency) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, frequency, frequency, pendingIntent);
}

From source file:com.commonsware.android.wakecast.PollReceiver.java

static void scheduleAlarms(Context ctxt) {
    AlarmManager mgr = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(ctxt, PollReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);

    mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + INITIAL_DELAY,
            PERIOD, pi);//from  ww  w .  j  a  v a  2 s. c  o m

}

From source file:com.commonsware.android.job.PollReceiver.java

static void scheduleExactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) {
    Intent i = new Intent(ctxt, PollReceiver.class).putExtra(EXTRA_PERIOD, period).putExtra(EXTRA_IS_DOWNLOAD,
            isDownload);//  ww w .j av  a  2 s . co  m
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);

    alarms.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi);
}

From source file:net.callmeike.android.alarmscheduler.scheduler.AlarmScheduler.java

public static void startSampleTask(Context ctxt) {
    int interval = ctxt.getResources().getInteger(R.integer.sample_task_interval);
    ((AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE)).setInexactRepeating(
            AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 100, interval * MS_PER_MINUTE,
            getTaskIntent(ctxt, SAMPLE_TASK));
    Log.d(TAG, "sample task started");
}

From source file:com.commonsware.android.deepbg.PollReceiver.java

static void scheduleExactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) {
    Intent i = buildBaseIntent(ctxt).putExtra(EXTRA_PERIOD, period).putExtra(EXTRA_IS_DOWNLOAD, isDownload);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
        Log.e("PollReceiver", "allow while idle");
        alarms.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + period, pi);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        alarms.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi);
    } else {//  w  w w. j  a  v  a 2  s . co  m
        alarms.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi);
    }
}

From source file:com.commonsware.android.job.PollReceiver.java

static void scheduleInexactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) {
    Intent i = new Intent(ctxt, PollReceiver.class).putExtra(EXTRA_IS_DOWNLOAD, isDownload);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);

    alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period,
            period, pi);//from   www . jav  a 2  s  .  c o  m
}

From source file:net.eledge.android.europeana.service.receiver.BlogCheckerReceiver.java

public void enableBlogChecker(Context context) {
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, BlogCheckerReceiver.class);
    blogCheckerIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, INTERVAL, INTERVAL,
            blogCheckerIntent);/*  w w w  . ja  va  2 s.c o m*/

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

    if (pm != null) {
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }
}

From source file:com.ivarprudnikov.sensors.OnBootBroadcastReceiver.java

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

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

    // Starts service responsible for sensor data storage
    Intent startSensorDataServiceIntent = new Intent(context, OnAlarmBroadcastReceiver.class);
    startSensorDataServiceIntent.setAction(Constants.INTENT_ACTION_TRIGGER_FROM_BOOT);
    PendingIntent pi1 = PendingIntent.getBroadcast(context, 0, startSensorDataServiceIntent, 0);
    mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + START_AT_OFFSET, pi1);

    // Registers alarms required for data export
    Intent startDataExportIntent = new Intent(context, OnExportAlarmBroadcastReceiver.class);
    startDataExportIntent.setAction(Constants.INTENT_ACTION_TRIGGER_FROM_BOOT);
    PendingIntent pi2 = PendingIntent.getBroadcast(context, 0, startSensorDataServiceIntent, 0);
    mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + START_AT_OFFSET, pi2);
}

From source file:com.commonsware.android.deepbg.PollReceiver.java

static void scheduleInexactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) {
    Intent i = buildBaseIntent(ctxt).putExtra(EXTRA_IS_DOWNLOAD, isDownload);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);

    alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period,
            period, pi);/*from   www .java2s .  com*/
}

From source file:me.acristoffers.tracker.AlarmReceiver.java

public static void setAlarm(final Context context) {
    try {/*from   www  . ja va  2s .com*/
        final Intent intent = new Intent(context, AlarmReceiver.class);
        final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

        final long fiveMinutes = 5 * 60 * 1000;

        final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
        final String minutes = sharedPref.getString("sync_interval", "15");

        long repeatMinutes;
        try {
            repeatMinutes = Long.parseLong(minutes) * 60 * 1000;
        } catch (NumberFormatException e) {
            repeatMinutes = 15 * 60 * 1000;
        }

        final boolean active = sharedPref.getBoolean("autosync", true);

        if (active) {
            alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, fiveMinutes, repeatMinutes,
                    pendingIntent);
        } else {
            alarmManager.cancel(pendingIntent);
        }
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}