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.hansel.myAlert.ReminderService.java

@Override
public void onCreate() {
    super.onCreate();
    //obtenemos el "nmero de intentos"
    getApplicationContext().registerReceiver(alarmReceiver, new IntentFilter(CANCEL_ALARM_BROADCAST));
    int count = PreferenciasHancel.getReminderCount(getApplicationContext());
    count++;/*from   ww  w . j  av a  2s  . c o  m*/
    PreferenciasHancel.setReminderCount(getApplicationContext(), count);
    Log.v("Conteo: " + count);
    if (count >= 3) {
        //detenemos la alarma del servicio de recordatorios. y lanzamos el servicio de Tracking 
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        am.cancel(Util.getReminderPendingIntennt(getApplicationContext()));
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(NOTIFICATION_ID);
        Log.v("Servicio de Rastreo....");
        Util.inicarServicio(getApplicationContext());

        startService(new Intent(getApplicationContext(), SendPanicService.class));
        stopSelf();
    } else {
        //mandamos una alerta de notificacin
        showNotifciation();
        playSound();
        mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        Vibra();
        Handler han = new Handler();
        run = new Runnable() {

            @Override
            public void run() {
                cancelAlarm();
                stopSelf();
            }
        };
        han.postDelayed(run, 1000 * 10);

        //alarma para "regresar" en caso que el usuario no de "click" en la notificacin
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        long due = System.currentTimeMillis() + (60000 * 3); // 3 minutos
        Log.v("Scheduling next update at " + new Date(due));
        am.set(AlarmManager.RTC_WAKEUP, due, Util.getReminderPendingIntennt(getApplicationContext()));

    }

}

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

@Override
public void pause() {
    //Cancel previous
    PendingIntent pendingIntent = createPendingIntent(mContext, mCurrentAlarmSchedule);
    AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pendingIntent);
    endAlarmService();// w  ww.j a  v  a 2 s  .  com
    int totalPauseTime = Utils.getDefaultPauseAmount(mContext);
    long delayTimeInMillis = totalPauseTime * Constants.secondsInMinute * Constants.millisecondsInSecond;
    long triggerTime = SystemClock.elapsedRealtime() + delayTimeInMillis;
    PendingIntent pausePendingIntent = createPausePendingIntent(mContext, mCurrentAlarmSchedule);
    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.SCHEDULE_PAUSED);
}

From source file:com.money.manager.ex.sync.SyncSchedulerBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = "";
    // by default, the action is ACTION_START. This is assumed on device boot.

    if (intent != null && !TextUtils.isEmpty(intent.getAction())) {
        action = intent.getAction();//w  w w .  ja  v a  2  s . co  m
        Timber.d("Sync scheduler request: %s", action);
    }

    Intent syncIntent = new Intent(context, SyncBroadcastReceiver.class);
    PendingIntent pendingSyncIntent = PendingIntent.getBroadcast(context, SyncConstants.REQUEST_PERIODIC_SYNC,
            syncIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    // PendingIntent.FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT

    AlarmManager alarmManager = getAlarmManager(context);

    // Cancel existing heartbeat.
    if (action.equals(ACTION_STOP)) {
        Timber.d("Stopping synchronization alarm.");

        alarmManager.cancel(pendingSyncIntent);
        return;
    }

    startHeartbeat(context, alarmManager, pendingSyncIntent);
}

From source file:com.chaitu.lmscalendar.ui.UrlDialog.java

@Override
public void onStart() {
    super.onStart();
    final AlertDialog dlg = (AlertDialog) getDialog();
    if (dlg == null)
        return;//www.j  a v  a  2 s.co m

    View.OnClickListener onClickTask;
    onClickTask = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String url = mTextCalendarUrl.getText().toString();
            String username = mTextUsername.getText().toString();
            String password = mTextPassword.getText().toString();
            String calendar = mTextPassword.getText().toString();
            long sync_interval = mSpinnerSyncInterval.getSelectedItemId();
            CalendarModel calendarModel = (CalendarModel) mSpinnerCalendar.getSelectedItem();
            int calID = calendarModel.getId();
            String calName = calendarModel.getName();

            /*if (!mActivity.setSource(url, null, username, password)) {
            TextView label = (TextView) dlg.findViewById(R.id.TextViewUrlError);
            label.setText(R.string.invalid_url);
            return;
            }*/

            Intent intent = new Intent(getActivity(), AlarmReceiver.class);
            intent.putExtra(AlarmReceiver.ACTION_ALARM, AlarmReceiver.ACTION_ALARM);
            final PendingIntent pIntent = PendingIntent.getBroadcast(getActivity(), 1234567, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            AlarmManager alarms = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
            alarms.cancel(pIntent);

            Settings settings = mActivity.getSettings();
            settings.putString(Settings.PREF_LASTURL, url);

            settings.putString(Settings.PREF_LASTURLUSERNAME, username);
            settings.putString(Settings.PREF_LASTURLPASSWORD, password);
            settings.putString(Settings.PREF_LASTCALENDARNAME, calName);
            settings.putInt(Settings.PREF_LASTCALENDARID, calID);
            settings.putInt(Settings.PREF_LASTSYNCINTERVAL, (int) sync_interval);
            mActivity.startIntent();
            dlg.dismiss();

        }
    };

    dlg.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(onClickTask);

}

From source file:net.vexelon.bgrates.ui.activities.MainActivity.java

public void cancelService() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}

From source file:org.zywx.wbpalmstar.platform.push.mqttpush.PushGetData2.java

private void stopKeepAlives() {
    Intent i = new Intent();
    i.setClass(mCtx, PushService.class);
    i.setAction(CLIENT_ID + ".KEEP_ALIVE");
    PendingIntent pi = PendingIntent.getService(mCtx, 0, i, 0);
    AlarmManager alarmMgr = (AlarmManager) mCtx.getSystemService(Service.ALARM_SERVICE);
    alarmMgr.cancel(pi);
}

From source file:Main.java

public static <T extends BroadcastReceiver> void scheduleUpdate(Context context, Class<T> clazz) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, clazz);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    Random random = new Random(System.currentTimeMillis());
    long offset = random.nextLong() % (12 * 60 * 60 * 1000);
    long interval = (24 * 60 * 60 * 1000) + offset;
    String prefKey = "pref_scheduled_monitor_config_update_" + clazz.getCanonicalName();
    long scheduledTime = preferences.getLong(prefKey, -1);

    if (scheduledTime == -1) {
        context.sendBroadcast(intent);//from  w w w. ja  va2s  .co m
    }

    if (scheduledTime <= System.currentTimeMillis()) {
        context.sendBroadcast(intent);
        scheduledTime = System.currentTimeMillis() + interval;
        preferences.edit().putLong(prefKey, scheduledTime).commit();
        Log.w("PeriodicActionUtils",
                "Scheduling for all new time: " + scheduledTime + " (" + clazz.getSimpleName() + ")");
    } else {
        Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime + " ("
                + clazz.getSimpleName() + ")");
    }

    am.cancel(sender);
    am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender);

    Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime + " (" + clazz.getSimpleName() + ")");
}

From source file:com.manumanu.alarmexample2.AlarmNotification.java

private void stop() {
    Log.i(TAG, "AlarmNotification.stop()");

    mTimer.cancel();//from  w w  w  .  jav a 2 s .  co  m
    readPreferences();
    //mRingtone = mRingtoneManager.getRingtone(this, Settings.System.DEFAULT_RINGTONE_URI);
    mRingtone.stop();
    mRingtoneManager.stopPreviousRingtone();
    if (mVibrate)
        mVibrator.cancel();
    //finish();
    PendingIntent sender;
    Intent intent;

    intent = new Intent(this, AlarmReceiver.class);
    sender = PendingIntent.getBroadcast(this, (int) mAlarm.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager mAlarmManager = (AlarmManager) getApplicationContext()
            .getSystemService(getApplicationContext().ALARM_SERVICE);
    mAlarmManager.cancel(sender);

}

From source file:org.fdroid.enigtext.service.KeyCachingService.java

private void startTimeoutIfAppropriate() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean timeoutEnabled = sharedPreferences
            .getBoolean(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_PREF, false);

    if ((activitiesRunning == 0) && (this.masterSecret != null) && timeoutEnabled && !isPassphraseDisabled()) {
        long timeoutMinutes = sharedPreferences
                .getInt(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_INTERVAL_PREF, 60 * 5);
        long timeoutMillis = timeoutMinutes * 60 * 1000;

        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  w w.  ja v a  2 s .  co  m*/
}

From source file:ch.fixme.status.Widget.java

public void onReceive(Context ctxt, Intent intent) {
    String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
        // Remove widget alarm
        int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        PendingIntent pi = PendingIntent.getService(ctxt, widgetId, getIntent(ctxt, widgetId), 0);
        AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
        am.cancel(pi);

        // remove preference
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
        Editor edit = prefs.edit();/*www .j av  a2  s  .  c  o m*/
        edit.remove(Main.PREF_API_URL_WIDGET + widgetId);
        edit.remove(Main.PREF_INIT_WIDGET + widgetId);
        edit.remove(Main.PREF_LAST_WIDGET + widgetId);
        edit.remove(Main.PREF_FORCE_WIDGET + widgetId);
        edit.commit();

        // Log.i(Main.TAG, "Remove widget alarm for id=" + widgetId);
    } else if (intent.hasExtra(WIDGET_IDS) && AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
        int[] ids = intent.getExtras().getIntArray(WIDGET_IDS);
        onUpdate(ctxt, AppWidgetManager.getInstance(ctxt), ids);
    } else
        super.onReceive(ctxt, intent);
}