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.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);
    endAlarmService();/*from  w  ww. j a  v a  2s  .  co  m*/
    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:org.roman.findme.MainActivity.java

void stopLocationService() {
    Intent intent = new Intent(this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1253, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}

From source file:com.capstone.transit.trans_it.RouteMap.java

@Override
protected void onPause() {
    super.onPause();
    stopService(positionsServiceIntent);
    positionsServiceIntent = new Intent(getApplicationContext(), RefreshPositionsService.class);
    final PendingIntent pendingIntent = PendingIntent.getService(this, 0, positionsServiceIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    alarm.cancel(pendingIntent);
}

From source file:com.jay.pea.mhealthapp2.utilityClasses.AlarmReceiver.java

public void CancelAlarm(Context context) {
    Intent intent = new Intent(context, AlarmReceiver.class);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(sender);
}

From source file:org.roman.findme.MainActivity.java

void startLocationService() {
    //        Intent intent = new Intent(this, AndroidLocationServices.class);
    //        startService(intent);

    Intent intent = new Intent(this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1253, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarm.cancel(pendingIntent);
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_HOUR,
            pendingIntent);//w ww .ja v a2 s. c o m

}

From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java

@Override
public void onDisabled(Context context) {
    super.onDisabled(context);

    // remove the update alarm if the last widget is gone
    Intent update = new Intent(UPDATE);
    PendingIntent pi = PendingIntent.getBroadcast(context, 195, update, 0);

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pi);
}

From source file:de.hero.vertretungsplan.CheckForAppUpdate.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    boolean setTimer = intent.getBooleanExtra("setTimer", false);
    boolean checkNow = intent.getBooleanExtra("checkNow", false);

    Intent i = new Intent(this, de.hero.vertretungsplan.CheckForAppUpdate.class);
    i.putExtra("checkNow", true);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    am.cancel(pi);
    Log.d("CheckForAppUpdate", "Alarm canceled");
    if (setTimer) {

        long lngInterval = AlarmManager.INTERVAL_DAY * 7;
        Log.d("CheckForAppUpdate", "Alarm set");
        am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY * 6, lngInterval, pi);
        //For debugging: after 10 seconds
        //am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 25000 , AlarmManager.INTERVAL_HOUR , pi);

    }// w w  w .  ja v  a  2s.  com

    if (checkNow) {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

        if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
            try {
                new HtmlWorkAppUpdate(this).execute(new URI(getString(R.string.htmlAdresseAktuelleVersion)));
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return START_NOT_STICKY;
}

From source file:com.near.chimerarevo.fragments.SettingsFragment.java

private void setAlarm(int sel, boolean isEnabled) {
    Intent intent = new Intent(getActivity().getApplicationContext(), NewsService.class);
    PendingIntent pintent = PendingIntent.getService(getActivity().getApplicationContext(), 0, intent, 0);
    AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);

    alarm.cancel(pintent);

    if (isEnabled) {
        long delay;
        switch (sel) {
        case 0://from www .  j a  v a 2 s  .  c  o  m
            delay = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
            break;
        case 1:
            delay = AlarmManager.INTERVAL_HALF_HOUR;
            break;
        case 2:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        case 3:
            delay = 2 * AlarmManager.INTERVAL_HOUR;
            break;
        case 4:
            delay = 3 * AlarmManager.INTERVAL_HOUR;
            break;
        case 5:
            delay = 6 * AlarmManager.INTERVAL_HOUR;
            break;
        case 6:
            delay = AlarmManager.INTERVAL_HALF_DAY;
            break;
        case 7:
            delay = AlarmManager.INTERVAL_DAY;
            break;
        default:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        }

        alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.uptimeMillis(), delay, pintent);
    }
}

From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java

@Override
public void unpause() {
    PendingIntent pendingIntent = createPausePendingIntent(mContext, mCurrentAlarmSchedule);
    AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pendingIntent);
    setRepeatingAlarm();//from  w  w w . ja  v  a  2 s . c  om
    Utils.setImageStatus(mContext, Constants.SCHEDULE_RUNNING);
}

From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java

@Override
public void cancelAlarm() {
    PendingIntent pendingIntent = createPendingIntent(mContext, mCurrentAlarmSchedule);
    AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pendingIntent);
    endAlarmService();//from   w  w  w.  j  a va2s  . com
    Utils.setImageStatus(mContext, Constants.NO_ALARM_RUNNING);
    Utils.setRunningScheduledAlarm(mContext, -1);
}