Example usage for android.app AlarmManager ELAPSED_REALTIME

List of usage examples for android.app AlarmManager ELAPSED_REALTIME

Introduction

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

Prototype

int ELAPSED_REALTIME

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

Click Source Link

Document

Alarm time in android.os.SystemClock#elapsedRealtime SystemClock.elapsedRealtime() (time since boot, including sleep).

Usage

From source file:de.wikilab.android.friendica01.Max.java

public static void runTimer(Context c) {
    Log.i("Friendica", "try runTimer");
    if (piTimerNotifications != null)
        return;//from w  w  w. java2  s. c o  m
    AlarmManager a = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
    piTimerNotifications = PendingIntent.getService(c, 1, new Intent(c, NotificationCheckerService.class), 0);
    a.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, AlarmManager.INTERVAL_FIFTEEN_MINUTES,
            piTimerNotifications);
    Toast.makeText(c, "Friendica: Notif. check timer run", Toast.LENGTH_SHORT).show();
    Log.i("Friendica", "done runTimer");
}

From source file:com.example.stacky.ScheduledMaintenanceService.java

/**
 * Reduce battery impact by waiting until the phone is no longer in standby mode before the alarm triggers
 *//*from ww w  .ja v  a  2  s. c  o m*/
@Override
protected void onHandleIntent(Intent intent) {
    System.out.println("got Intent ");

    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 25000,
            25000, startAlarmPendingIntent);

    //lastTime=System.currentTimeMillis();

    displayNotificationOne();

}

From source file:com.piggate.samples.PiggateLoginService.Service_Notify.java

@Override
public void onTaskRemoved(Intent rootIntent) {
    Intent restartService = new Intent(getApplicationContext(), this.getClass());
    restartService.setPackage(getPackageName());
    PendingIntent restartServicePI = PendingIntent.getService(getApplicationContext(), 1, restartService,
            PendingIntent.FLAG_ONE_SHOT);
    AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePI);
}

From source file:com.appsaur.tarucassist.AlarmReceiver.java

public void setAlarm(Context context, Calendar calendar, int ID) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Put Reminder ID in Intent Extra
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
    mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // Calculate notification time
    Calendar c = Calendar.getInstance();
    long currentTime = c.getTimeInMillis();
    long diffTime = calendar.getTimeInMillis() - currentTime;

    // Start alarm using notification time
    mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, mPendingIntent);

    // Restart alarm if device is rebooted
    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:com.android.anton.pushnotificationwithgcm.GCMUtil.MyGcmListenerService.java

@Override
public void onTaskRemoved(Intent rootIntent) {
    Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass());
    restartServiceIntent.setPackage(getPackageName());
    PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1,
            restartServiceIntent, PendingIntent.FLAG_ONE_SHOT);

    AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000,
            restartServicePendingIntent);

    super.onTaskRemoved(rootIntent);
}

From source file:cn.studyjams.s2.sj0119.NForget.AlarmReceiver.java

public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Put Reminder ID in Intent Extra
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
    mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // Calculate notification timein
    Calendar c = Calendar.getInstance();
    long currentTime = c.getTimeInMillis();
    long diffTime = calendar.getTimeInMillis() - currentTime;

    // Start alarm using initial notification time and repeat interval time
    mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime,
            RepeatTime, mPendingIntent);

    // Restart alarm if device is rebooted
    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:com.appsaur.tarucassist.AutomuteAlarmReceiver.java

public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Put Reminder ID in Intent Extra
    Intent intent = new Intent(context, AutomuteAlarmReceiver.class);
    intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
    mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // Calculate notification timein
    Calendar c = Calendar.getInstance();
    long currentTime = c.getTimeInMillis();
    long diffTime = calendar.getTimeInMillis() - currentTime;

    // Start alarm using initial notification time and repeat interval time
    mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime,
            RepeatTime, mPendingIntent);

    // Restart alarm if device is rebooted
    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:com.sean.takeastand.alarmprocess.UnscheduledRepeatingAlarm.java

@Override
public void pause() {
    //Cancel previous
    PendingIntent pendingIntent = createPendingIntent(mContext);
    AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pendingIntent);/*  w  ww .j  av  a2s .  c  om*/
    endAlarmService();
    int totalPauseTime = Utils.getDefaultPauseAmount(mContext);
    long delayTimeInMillis = totalPauseTime * Constants.secondsInMinute * Constants.millisecondsInSecond;
    long triggerTime = SystemClock.elapsedRealtime() + delayTimeInMillis;
    PendingIntent pausePendingIntent = createPausePendingIntent(mContext);
    am.set(AlarmManager.ELAPSED_REALTIME, triggerTime, pausePendingIntent);
    Calendar pausedUntilTime = Calendar.getInstance();
    pausedUntilTime.add(Calendar.MINUTE, Utils.getDefaultPauseAmount(mContext));
    Utils.setPausedTime(pausedUntilTime, mContext);
    Utils.setImageStatus(mContext, Constants.NON_SCHEDULE_PAUSED);
}

From source file:au.com.smarttrace.beacons.BluetoothService.java

private void connect() {
    btScanner = btAdapter.getBluetoothLeScanner();
    if (btScanner != null && btAdapter.isEnabled()) {

        Log.d(TAG, "START SCANNING!");
        btScanner.startScan(btFilters, btSettings, scanCallback);
        scanning = true;//  w ww . ja va 2 s  .c om
        sendChange(true);

        //XXX: workaround to avoid bluetooth scan halt
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        Intent intent = new Intent(BluetoothService.ACTION_RESCAN, null, this, BluetoothService.class);
        alarm.setExact(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 15000l,
                PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));

        //         future = executor.schedule(this, DELAY_REPEAT_SCAN, TimeUnit.SECONDS);
    }
}

From source file:info.papdt.blacklight.support.Utility.java

public static void startServiceAlarm(Context context, Class<?> service, long interval) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, service);
    PendingIntent p = PendingIntent.getService(context, REQUEST_CODE, i, PendingIntent.FLAG_CANCEL_CURRENT);
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, interval, p);
}