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:com.oliversride.wordryo.UpdateCheckReceiver.java

public static void restartTimer(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    Intent intent = new Intent(context, UpdateCheckReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    am.cancel(pi);

    long interval_millis = INTERVAL_ONEDAY;
    if (!devOK(context)) {
        interval_millis *= INTERVAL_NDAYS;
    }/*from  w  w w.  ja v  a2s  .  c o m*/
    interval_millis = (interval_millis / 2) + Math.abs(Utils.nextRandomInt() % interval_millis);
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime() + interval_millis, interval_millis, pi);
}

From source file:org.smssecure.smssecure.notifications.MessageNotifier.java

public static void clearReminder(Context context) {
    Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}

From source file:com.jtechme.apphub.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);
        Utils.debugLog(TAG, "Update scheduler alarm set");
    } else {//www  . j a  va 2  s  .  com
        Utils.debugLog(TAG, "Update scheduler alarm not set");
    }

}

From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java

private static void clearReminder(Context context) {
    Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}

From source file:com.granita.tasks.notification.NotificationActionUtils.java

/**
 * Cancels the undo timeout for a notification action. This should be called if the undo notification is clicked (to prevent the action from being performed
 * anyway) or cleared (since we have already performed the action).
 */// w  w  w. ja v a 2 s. c  o m
public static void cancelUndoTimeout(final Context context, final NotificationAction notificationAction) {
    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent pendingIntent = createUndoTimeoutPendingIntent(context, notificationAction);
    alarmManager.cancel(pendingIntent);
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.receiver.NotificationHelper.java

/**
 * Schedules to be woken up at the next notification time.
 *///  ww w . ja  va 2  s  . c o  m
private static void scheduleNext(Context context) {
    // Get first future notification
    final Calendar now = Calendar.getInstance();
    final List<cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification> notifications = cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification
            .getNotificationsWithTime(context, now.getTimeInMillis(), false);

    // if not empty, schedule alarm wake up
    if (!notifications.isEmpty()) {
        // at first's time
        // Create a new PendingIntent and add it to the AlarmManager
        Intent intent = new Intent(Intent.ACTION_RUN);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        am.cancel(pendingIntent);
        am.set(AlarmManager.RTC_WAKEUP, notifications.get(0).time, pendingIntent);
    }

    monitorUri(context);
}

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  ww.j  ava2s . c  o 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:com.metinkale.prayerapp.vakit.AlarmReceiver.java

public static void setAlarm(Context c, Alarm alarm) {
    AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);

    Intent i = new Intent(c, WakefulReceiver.class);
    if (alarm != null) {
        i.putExtra("json", alarm.toString());
        int id = alarm.hashCode();
        PendingIntent service = PendingIntent.getBroadcast(c, id, i, PendingIntent.FLAG_UPDATE_CURRENT);

        am.cancel(service);

        App.setExact(am, AlarmManager.RTC_WAKEUP, alarm.time, service);
    }//ww w.  j a  v  a 2s  .co  m

}

From source file:de.schildbach.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(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//from  w w  w  . 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.pixmob.freemobile.netstat.SyncService.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, SyncService.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 w  w  w .j  a v a 2s. c  om

        // 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");
        }
    }
}