Example usage for android.app AlarmManager cancel

List of usage examples for android.app AlarmManager cancel

Introduction

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

Prototype

public void cancel(OnAlarmListener listener) 

Source Link

Document

Remove any alarm scheduled to be delivered to the given OnAlarmListener .

Usage

From source file:org.videolan.vlc.gui.video.AdvOptionsDialog.java

public static void setSleep(Context context, Calendar time) {
    AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(VLCApplication.SLEEP_INTENT);
    PendingIntent sleepPendingIntent = PendingIntent.getBroadcast(VLCApplication.getAppContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (time != null) {
        alarmMgr.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), sleepPendingIntent);
    } else {//  w  w w.  jav a  2  s .c  o  m
        alarmMgr.cancel(sleepPendingIntent);
    }
    VLCApplication.sPlayerSleepTime = time;
}

From source file:com.smarthome.deskclock.Alarms.java

/**
 * Disables alert in AlarmManger and StatusBar.
 *
 * @param id Alarm ID.//  w  w  w . j av  a  2 s .  c  o m
 */
static void disableAlert(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, new Intent(ALARM_ALERT_ACTION),
            PendingIntent.FLAG_CANCEL_CURRENT);
    am.cancel(sender);
    setStatusBarIcon(context, false);
    saveNextAlarm(context, "");
}

From source file:biz.wiz.android.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(@Nonnull final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    final long lastUsedAgo = config.getLastUsedAgo();

    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else//w ww  . j  a v a 2 s  .  co m
        alarmInterval = AlarmManager.INTERVAL_DAY;

    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
            lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent alarmIntent = PendingIntent.getService(context, 0,
            new Intent(context, BlockchainServiceImpl.class), 0);
    alarmManager.cancel(alarmIntent);

    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY,
            alarmIntent);
}

From source file:org.hopestarter.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context),
            context.getResources());/*www.  j  ava  2  s  .com*/
    final long lastUsedAgo = config.getLastUsedAgo();

    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else
        alarmInterval = AlarmManager.INTERVAL_DAY;

    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
            lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent alarmIntent = PendingIntent.getService(context, 0,
            new Intent(context, BlockchainServiceImpl.class), 0);
    alarmManager.cancel(alarmIntent);

    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY,
            alarmIntent);
}

From source file:org.ohmage.reminders.notif.Notifier.java

private static void cancelAlarm(Context context, String action) {
    AlarmManager alarmMan = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    Intent i = new Intent(context, NotifReceiver.class).setAction(action);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_NO_CREATE);

    if (pi != null) {
        alarmMan.cancel(pi);
        pi.cancel();//from   w  w w  .ja  v a2  s.  c  o  m
    }
}

From source file:com.google.android.apps.dashclock.PeriodicExtensionRefreshReceiver.java

/**
 * Sets the refresh schedule if one isn't set already.
 *//* w ww .j  a v  a 2 s. c  o m*/
public static void updateExtensionsAndEnsurePeriodicRefresh(final Context context) {
    LOGD(TAG, "updateExtensionsAndEnsurePeriodicRefresh");
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Update all extensions now.
    context.startService(getUpdateAllExtensionsIntent(context, DashClockExtension.UPDATE_REASON_MANUAL));

    // Schedule an alarm for every 30 minutes; it will not wake up the device;
    // it will be handled only once the device is awake. The first time that this
    // alarm can go off is in 15 minutes, and the latest time it will go off is
    // 45 minutes from now.
    PendingIntent pi = PendingIntent.getBroadcast(context, 0,
            new Intent(context, PeriodicExtensionRefreshReceiver.class).setAction(ACTION_PERIODIC_ALARM),
            PendingIntent.FLAG_UPDATE_CURRENT);
    am.cancel(pi);
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime() + 15 * MINUTES_MILLIS, AlarmManager.INTERVAL_HALF_HOUR, pi);
}

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);

    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);
        }//from   ww  w  . j  av a2  s  .c o  m

        // 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:nu.yona.app.utils.AppUtils.java

@TargetApi(Build.VERSION_CODES.O)
public static void cancelPendingWakeUpAlarms(Context context) {
    Intent alarmIntent = new Intent(context, YonaReceiver.class);
    alarmIntent.setAction(AppConstant.WAKE_UP);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}

From source file:id.ridon.keude.UpdateService.java

public static void schedule(Context ctx) {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0");
    int interval = Integer.parseInt(sint);

    Intent intent = new Intent(ctx, UpdateService.class);
    PendingIntent pending = PendingIntent.getService(ctx, 0, intent, 0);

    AlarmManager alarm = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    alarm.cancel(pending);
    if (interval > 0) {
        alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 5000,
                AlarmManager.INTERVAL_HOUR, pending);
        Log.d("Keude", "Update scheduler alarm set");
    } else {//from w w w.j ava2 s.c  om
        Log.d("Keude", "Update scheduler alarm not set");
    }

}

From source file:com.ksk.droidbatterybooster.provider.TimeSchedule.java

/**
 * @param id Schedule ID.// ww  w  .  j av  a  2s  . c  o m
 * 
 */
static void disableAction(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, new Intent(EXECUTE_SCHEDULE_ACTION),
            PendingIntent.FLAG_CANCEL_CURRENT);
    am.cancel(sender);
    saveNextAlarm(context, "");
}