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:ru.glesik.wifireminders.AlarmService.java

public void stopAlarm() {
    AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
    alarmManager.cancel(pendingIntent);
    // Disable boot receiver
    ComponentName receiver = new ComponentName(this, BootReceiver.class);
    PackageManager pm = this.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java

/** 
 * Update an existing notification /* w w w .ja  v a2  s  .  co m*/
 * 
 * @param updates JSONObject with update-content
 */
public void update(JSONObject updates) {
    String id = updates.optString("id", "0");

    // update shared preferences
    SharedPreferences settings = getSharedPreferences();
    Map<String, ?> alarms = settings.getAll();
    JSONObject arguments;
    try {
        arguments = new JSONObject(alarms.get(id).toString());
    } catch (JSONException e) {
        Log.e("NotificationWrapper", "Update failed. No Notification available for the given id: " + id);
        return;
    }
    arguments = updateArguments(arguments, updates);

    // cancel existing alarm
    Intent intent = new Intent(context, receiver).setAction("" + id);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    AlarmManager am = getAlarmManager();
    am.cancel(pi);

    //add new alarm
    Options options = new Options(context).parse(arguments);
    schedule(options);
}

From source file:com.example.android.wearable.timer.TimerNotificationService.java

private void deleteTimer() {
    cancelCountdownNotification();/*from   w ww. j ava  2s.  com*/

    AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(Constants.ACTION_SHOW_ALARM, null, this, TimerNotificationService.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarm.cancel(pendingIntent);

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Timer deleted.");
    }
}

From source file:org.bwgz.quotation.service.QuotationService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, String.format("onHandleIntent - intent: %s (%s)", intent, new Date().toString()));

    SharedPreferences preferences = getSharedPreferences(QuotationApplication.APPLICATION_PREFERENCES,
            Context.MODE_PRIVATE);
    long modified = preferences.getLong(QuotationApplication.APPLICATION_PREFERENCE_QUOTATION_PICKS_MODIFIED,
            0);//from   w  w w.  ja  v  a 2s . c  om

    if (modified + PICKS_PERIOD < System.currentTimeMillis()) {
        getContentResolver().delete(PickQuotation.CONTENT_URI, null, null);
        getContentResolver().delete(PickPerson.CONTENT_URI, null, null);
        getContentResolver().delete(PickSubject.CONTENT_URI, null, null);

        FreebaseIdLoader freebaseIdLoader = FreebaseIdLoader.getInstance(getApplicationContext());
        List<Pick> quotationPicks = freebaseIdLoader.getRandomQuotationPicks(PICK_SIZE);
        List<Pick> authorPicks = freebaseIdLoader.getRandomAuthorPicks(PICK_SIZE);
        List<Pick> subjectPicks = freebaseIdLoader.getRandomSubjectPicks(PICK_SIZE);

        for (int i = 0; i < PICK_SIZE; i++) {
            getContentResolver()
                    .query(PickQuotation.withAppendedId(quotationPicks.get(i).getId()), null, null, null, null)
                    .close();
            getContentResolver()
                    .query(PickPerson.withAppendedId(authorPicks.get(i).getId()), null, null, null, null)
                    .close();
            getContentResolver()
                    .query(PickSubject.withAppendedId(subjectPicks.get(i).getId()), null, null, null, null)
                    .close();
        }

        SharedPreferences.Editor editor = preferences.edit();
        modified = System.currentTimeMillis();
        editor.putLong(QuotationApplication.APPLICATION_PREFERENCE_QUOTATION_PICKS_MODIFIED, modified);
        editor.putLong(QuotationApplication.APPLICATION_PREFERENCE_PERSON_PICKS_MODIFIED, modified);
        editor.putLong(QuotationApplication.APPLICATION_PREFERENCE_SUBJECT_PICKS_MODIFIED, modified);
        editor.commit();
    }

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(this, QuotationAlarmReceiver.class), 0);
    alarmManager.cancel(alarmIntent);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 2);
    calendar.set(Calendar.MINUTE, random.nextInt(60));
    calendar.set(Calendar.SECOND, random.nextInt(60));
    alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis() + PICKS_PERIOD, alarmIntent);

    LocalBroadcastManager.getInstance(this)
            .sendBroadcast(new Intent(BROADCAST_ACTION).putExtra(EXTENDED_DATA_STATUS, true));
}

From source file:org.smssecure.smssecure.service.KeyCachingService.java

private void startTimeoutIfAppropriate() {
    boolean timeoutEnabled = SilencePreferences.isPassphraseTimeoutEnabled(this);

    if ((activitiesRunning == 0) && (KeyCachingService.masterSecret != null) && timeoutEnabled
            && !SilencePreferences.isPasswordDisabled(this)) {
        long timeoutMinutes = SilencePreferences.getPassphraseTimeoutInterval(this);
        long timeoutMillis = TimeUnit.MINUTES.toMillis(timeoutMinutes);

        Log.w("KeyCachingService", "Starting timeout: " + timeoutMillis);

        AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE);
        alarmManager.cancel(pending);
        alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + timeoutMillis, pending);
    }//from  w  w w .j  av a2 s. c o  m
}

From source file:com.meiste.greg.ptw.WidgetProvider.java

@Override
public void onDisabled(final Context context) {
    Util.log("WidgetProvider.onDisabled");

    final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.cancel(getAlarmIntent(context));

    Util.getState(context).edit().putBoolean(WIDGET_STATE, false).apply();
    Analytics.trackEvent(context, "Widget", "state", "disabled");
}

From source file:com.tingtingapps.securesms.service.KeyCachingService.java

private void startTimeoutIfAppropriate() {
    boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(this);

    if ((activitiesRunning == 0) && (KeyCachingService.masterSecret != null) && timeoutEnabled
            && !TextSecurePreferences.isPasswordDisabled(this)) {
        long timeoutMinutes = TextSecurePreferences.getPassphraseTimeoutInterval(this);
        long timeoutMillis = TimeUnit.MINUTES.toMillis(timeoutMinutes);

        Log.w("KeyCachingService", "Starting timeout: " + timeoutMillis);

        AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE);
        alarmManager.cancel(pending);
        alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + timeoutMillis, pending);
    }//w  ww  .j  a v  a  2 s  .c o m
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

public static long setUpdateAlarm(Context context, boolean initial) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    Intent alarmintent = new Intent(context, AlarmReceiver.class);
    alarmintent.setAction(AlarmReceiver.ALARM_UPDATE);

    PendingIntent pendingintent = PendingIntent.getBroadcast(context, 0, alarmintent, 0);

    MyApp.LogDebug(LOG_TAG, "set update alarm");
    long next_fetch;
    long interval;
    Time t = new Time();
    t.setToNow();/*from  w  w w .  jav a  2 s .c  o  m*/
    long now = t.toMillis(true);

    if ((now >= MyApp.first_day_start) && (now < MyApp.last_day_end)) {
        interval = 2 * AlarmManager.INTERVAL_HOUR;
        next_fetch = now + interval;
    } else if (now >= MyApp.last_day_end) {
        MyApp.LogDebug(LOG_TAG, "cancel alarm post congress");
        alarmManager.cancel(pendingintent);
        return 0;
    } else {
        interval = AlarmManager.INTERVAL_DAY;
        next_fetch = now + interval;
    }

    if ((now < MyApp.first_day_start) && ((now + AlarmManager.INTERVAL_DAY) >= MyApp.first_day_start)) {
        next_fetch = MyApp.first_day_start;
        interval = 2 * AlarmManager.INTERVAL_HOUR;
        if (!initial) {
            MyApp.LogDebug(LOG_TAG, "update alarm to interval " + interval + ", next in " + (next_fetch - now));
            alarmManager.cancel(pendingintent);
            alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent);
        }
    }

    if (initial) {
        MyApp.LogDebug(LOG_TAG,
                "set initial alarm to interval " + interval + ", next in " + (next_fetch - now));
        alarmManager.cancel(pendingintent);
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent);
    }

    return interval;
}

From source file:org.croudtrip.activities.MainActivity.java

@Override
public void init(Bundle savedInstanceState) {

    // Configure Navigation Drawer
    this.disableLearningPattern();
    this.allowArrowAnimation();
    this.setBackPattern(MaterialNavigationDrawer.BACKPATTERN_BACK_TO_FIRST);
    this.setDrawerHeaderImage(R.drawable.background_drawer);

    // Get all the saved user data to display some info in the navigation drawer
    showUserInfoInNavigationDrawer();/* w  w  w.  j ava  2  s  .co  m*/

    SharedPreferences prefs = getSharedPreferences(Constants.SHARED_PREF_FILE_PREFERENCES,
            Context.MODE_PRIVATE);

    // Start timer to update the user's offers all the time
    if (AccountManager.isUserLoggedIn(this)) {
        Intent alarmIntent = new Intent(this, LocationUploadTimerReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);

        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarmManager.cancel(pendingIntent);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 120 * 1000,
                pendingIntent);
    }

    // Subscribe to location updates
    LocationRequest request = LocationRequest.create() //standard GMS LocationRequest
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(10000);

    ReactiveLocationProvider locationProvider = new ReactiveLocationProvider(this);
    Subscription locationUpdateSubscription = locationProvider.getUpdatedLocation(request)
            .subscribe(new Action1<Location>() {
                @Override
                public void call(Location location) {
                    locationUpdater.setLastLocation(location);
                }
            });

    subscriptions.add(locationUpdateSubscription);

    // GPS availability
    if (!GPSavailable()) {
        checkForGPS();
    }

    // Registration for GCM, if we are not registered yet
    if (!gcmManager.isRegistered()) {
        Subscription subscription = gcmManager.register().compose(new DefaultTransformer<Void>()).retry(3)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        Timber.d("Registered at GCM.");
                    }
                }, new CrashCallback(this, "failed to register for GCM"));
        subscriptions.add(subscription);
    }

    fillNavigationDrawer();
}

From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java

public ScheduledNotification cancelNotification(String tag) {
    LOG.v(NotificationPlugin.TAG, "cancelNotification: " + tag);
    SharedPreferences prefs = getPrefs();
    SharedPreferences.Editor editor = prefs.edit();

    Map<String, ?> notifications = prefs.getAll();
    ScheduledNotification notification = null;

    for (String key : notifications.keySet()) {
        try {/*from  w  w  w .  j a  v a 2s.c  o  m*/
            JSONObject value = new JSONObject(notifications.get(key).toString());
            String ntag = value.optString("tag");
            LOG.v(NotificationPlugin.TAG, "checking Notification: " + value.toString());
            if (ntag != null && ntag.equals(tag)) {
                LOG.v(NotificationPlugin.TAG, "found Notification: " + value.toString());
                notification = new ScheduledNotification(value.optString("title", null), value);

                editor.remove(key);

                LOG.v(NotificationPlugin.TAG, "unscheduling Notification: ");
                //unschedule the alarm
                Intent intent = new Intent(context, TriggerReceiver.class);
                intent.setAction(ntag);

                PendingIntent pi = PendingIntent.getBroadcast(context, INTENT_REQUEST_CODE, intent,
                        PendingIntent.FLAG_CANCEL_CURRENT);

                AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                alarmManager.cancel(pi);
            }
        } catch (JSONException e) {
        }
    }

    editor.commit();

    if (notification != null) {
        LOG.v(NotificationPlugin.TAG, "returning Notification " + notification.toString());
    } else {
        LOG.v(NotificationPlugin.TAG, "could not find Notification " + tag);
    }

    return notification;
}