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:opensource.zeocompanion.ZeoCompanionApplication.java

private void configAlarmManagerToPrefs() {
    // setup a daily alarm if auto-emailing is enabled
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabledAutoEmail = prefs.getBoolean("email_auto_enable", false);
    boolean enabledDatabaseReplicate = prefs.getBoolean("database_replicate_zeo", false);
    long desiredTOD = prefs.getLong("email_auto_send_time", 0); // will default to midnight
    long configuredTOD = prefs.getLong("email_auto_send_time_configured", 0); // will default to midnight

    // determine whether there is an active AlarmManager entry that we have established
    AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    Intent intentCheck = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class);
    intentCheck.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC);
    PendingIntent existingPi = PendingIntent.getBroadcast(this, 0, intentCheck, PendingIntent.FLAG_NO_CREATE);

    if (enabledAutoEmail || enabledDatabaseReplicate) {
        // Daily AlarmManager is needed
        if (existingPi != null && desiredTOD != configuredTOD) {
            // there is an existing AlarmManager entry, but it has the incorrect starting time-of-day;
            // so cancel it, and rebuild a new one
            Intent intent1 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class);
            intent1.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC);
            PendingIntent pi1 = PendingIntent.getBroadcast(this, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT);
            am.cancel(pi1);
            pi1.cancel();/*from w  ww. ja  v  a 2s . c om*/
            existingPi = null;
        }
        if (existingPi == null) {
            // there is no existing AlarmManager entry, so create it
            Date dt = new Date(desiredTOD);
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.HOUR_OF_DAY, dt.getHours());
            calendar.set(Calendar.MINUTE, dt.getMinutes());
            calendar.set(Calendar.SECOND, dt.getSeconds());
            Intent intent2 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class);
            intent2.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC);
            PendingIntent pi2 = PendingIntent.getBroadcast(this, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
            am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                    pi2);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putLong("email_auto_send_time_configured", desiredTOD);
            editor.commit();
        }

    } else {
        // Daily AlarmManager is not needed
        if (existingPi != null) {
            // there is an AlarmManager entry pending; need to cancel it
            Intent intent3 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class);
            intent3.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC);
            PendingIntent pi3 = PendingIntent.getBroadcast(this, 0, intent3, PendingIntent.FLAG_CANCEL_CURRENT);
            am.cancel(pi3);
            pi3.cancel();
        }
    }
}

From source file:com.gpsmobitrack.gpstracker.MenuItems.SettingsPage.java

/**
 *  Background updates show ON or OFF//from  w w w .j av a 2 s. co  m
 */
private void showAlert(String Message, String Title, final int alertCode) {
    final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCancelable(false);
    dialog.setContentView(R.layout.alert_dialog_main);
    final TextView alertTitle = (TextView) dialog.findViewById(R.id.alert_title);
    final TextView alertMsg = (TextView) dialog.findViewById(R.id.alert_msg);
    final EditText alertEditTxt = (EditText) dialog.findViewById(R.id.alert_edit_txt);
    Button okBtn = (Button) dialog.findViewById(R.id.alert_ok_btn);
    Button cancelBtn = (Button) dialog.findViewById(R.id.alert_cancel_btn);
    alertTitle.setText(Title);
    alertMsg.setText(Message);
    alertEditTxt.setVisibility(View.GONE);
    if (alertCode == 0 || alertCode == UPDATE_INT || alertCode == 7) {
        cancelBtn.setVisibility(View.VISIBLE);
    } else {
        cancelBtn.setVisibility(View.GONE);
    }
    cancelBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            if (alertCode == 7) {
                backUpdateToggle.setChecked(true);
                editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, true);
                editor.commit();
            }
        }
    });
    okBtn.setOnClickListener(new OnClickListener() {
        @SuppressWarnings("unused")
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            if (alertCode == 3 || alertCode == 4) {

                session.logoutUser(getActivity());
                Intent i = new Intent(getActivity(), Login.class);
                startActivity(i);
                getActivity().finish();
            } else if (alertCode == 0) {
                deactivateAcc();
            } else if (alertCode == UPDATE_INT) {
                getActivity().finish();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("market://details?id=com.gpstracker.pro"));
                startActivity(intent);
            } else if (alertCode == 7) {
                backUpdateToggle.setChecked(false);
                editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, false);
                editor.commit();
                AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
                Calendar cal = Calendar.getInstance();
                Intent intent2 = new Intent(getActivity(), BackgroundService.class);
                PendingIntent pintent = PendingIntent.getService(getActivity(), 0, intent2, 0);
                if (PendingIntent.getService(getActivity(), 0, intent2, PendingIntent.FLAG_NO_CREATE) != null) {
                    alarm.cancel(pintent);
                }
            }
        }
    });
    dialog.show();
}

From source file:knayi.delevadriver.AvaliableJobDetailActivity.java

private void cancelAlarmManager() {
    Log.d("TAG", "cancelAlarmManager");

    Context context = getBaseContext();
    //Intent gpsTrackerIntent = new Intent(context, GpsTrackerAlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, gpsTrackerIntent, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}

From source file:com.t2.compassionMeditation.MeditationActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();

    Log.i(TAG, this.getClass().getSimpleName() + ".onDestroy()");

    if (mInternalSensorMonitoring) {
        // And cancel the alarm.
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.cancel(mBigBrotherService);

        Intent intent = new Intent();
        intent.setAction(BigBrotherConstants.ACTION_COMMAND_BROADCAST);
        intent.putExtra("message", BigBrotherConstants.SERVICE_OFF);
        sendBroadcast(intent);/*from   w w  w  .  j a v  a2  s .c  o  m*/

        // Tell the user about what we did.
        Toast.makeText(MeditationActivity.this, R.string.service_unscheduled, Toast.LENGTH_LONG).show();
    }

    // Send stop command to every shimmer device
    // You might think that it would be better to iterate through the mBioSensors table
    // instead of the mBioParameters table but it's actually easier this way
    for (GraphBioParameter param : mBioParameters) {
        if (param.isShimmer && param.shimmerNode != null) {
            ShimmerNonSpineSetupSensor setup = new ShimmerNonSpineSetupSensor();
            setup.setSensor(param.shimmerSensorConstant);

            String deviceAddress = SharedPref.getDeviceForParam(this, param.title1);
            if (deviceAddress != null) {

                setup.setBtAddress(Util.AsciiBTAddressToBytes(deviceAddress));
                setup.setCommand(ShimmerNonSpineSetupSensor.SHIMMER_COMMAND_STOPPED);

                Log.i(TAG, String.format("Setting up Shimmer sensor: %s (%s) (%d) SHIMMER_COMMAND_STOPPED",
                        param.shimmerNode.getPhysicalID(), deviceAddress, param.shimmerSensorConstant));
                mManager.setup(param.shimmerNode, setup);
            }
        }
    }

    if (mMediaPlayer != null) {
        mMediaPlayer.stop();
        mMediaPlayer.release();
        mMediaPlayer = null;
    }

    this.unregisterReceiver(this.mCommandReceiver);

    mDataOutHandler.close();

}

From source file:com.negaheno.android.NotificationsController.java

private void scheduleNotificationRepeat() {
    try {/*from   www.  j  a v a 2 s.c  o  m*/
        AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
        PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0,
                new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0);
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        int minutes = preferences.getInt("repeat_messages", 60);
        if (minutes > 0 && personal_count > 0) {
            alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000,
                    pintent);
        } else {
            alarm.cancel(pintent);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:org.nerdcircus.android.klaxon.Notifier.java

@Override
public void onReceive(Context context, Intent intent) {
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);

    if (intent.getAction().equals(Pager.PAGE_RECEIVED)) {
        Log.d(TAG, "new page received. notifying.");

        //get subject line of page, for notification.
        Cursor cursor = context.getContentResolver().query(intent.getData(),
                new String[] { Pager.Pages._ID, Pager.Pages.SUBJECT }, null, null, null);
        cursor.moveToFirst();/*from ww  w.ja v  a2s  . c  o  m*/
        String page_subj = cursor.getString(cursor.getColumnIndex(Pager.Pages.SUBJECT));

        Notification n = getNotification(context, page_subj);
        n.sound = null; //no noise initially. wait for the delayed ANNOY action below.
        nm.notify(R.string.notify_page, n);

        Intent i = new Intent(Pager.ANNOY_ACTION);
        //we cant use data here, because it makes the silencing fail.
        i.putExtra("notification_text", page_subj);
        PendingIntent annoyintent = PendingIntent.getBroadcast(context, 0, i,
                PendingIntent.FLAG_CANCEL_CURRENT);

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

        Log.d(TAG, "notifcation interval: " + prefs.getString("notification_interval", "unknown"));
        long repeat_interval_ms = Integer.valueOf(prefs.getString("notification_interval", "20000"))
                .longValue();
        Log.d(TAG, "notifcation interval: " + repeat_interval_ms);

        // 500 ms delay, to prevent the regular text message noise from stomping on us.
        am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, repeat_interval_ms,
                annoyintent);
    } else if (intent.getAction().equals(Pager.SILENCE_ACTION)) {
        Log.d(TAG, "cancelling the notification...");
        Intent i = new Intent(Pager.ANNOY_ACTION);
        PendingIntent annoyintent = PendingIntent.getBroadcast(context, 0, i,
                PendingIntent.FLAG_CANCEL_CURRENT);
        am.cancel(annoyintent);
        nm.cancel(R.string.notify_page);
    } else if (intent.getAction().equals(Pager.ANNOY_ACTION)) {
        Log.e(TAG, "got annoy intent. annoying.");
        //just be annoying.
        Notification n = getNotification(context, intent.getStringExtra("notification_text"));
        nm.notify(R.string.notify_page, n);
    } else if (intent.getAction().equals("org.nerdcircus.android.klaxon.REPLY_SENT")) {
        //a reply was sent. update state in the db.
        if (Activity.RESULT_OK == getResultCode()) {
            Log.d(TAG, "reply successful. updating ack status..");
            //result was sent. update state.
            updateAckStatus(context, intent.getData(), intent.getIntExtra(Pager.EXTRA_NEW_ACK_STATUS, 0));
        } else {
            Log.e(TAG, "reply failed!!! doing nothing.");
        }
    } else {
        Log.e(TAG, "Uncaught Action:" + intent.getAction());
    }

}

From source file:com.android.exchange.ExchangeService.java

private void clearAlarm(long id) {
    synchronized (mPendingIntents) {
        PendingIntent pi = mPendingIntents.get(id);
        if (pi != null) {
            AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
            alarmManager.cancel(pi);
            //log("+Alarm cleared for " + alarmOwner(id));
            mPendingIntents.remove(id);/* w  w  w . j av  a 2 s.com*/
        }
    }
}

From source file:com.android.exchange.ExchangeService.java

private void clearAlarms() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    synchronized (mPendingIntents) {
        for (PendingIntent pi : mPendingIntents.values()) {
            alarmManager.cancel(pi);
        }/*  w w w. ja  va  2 s.c o m*/
        mPendingIntents.clear();
    }
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

void cancelIdleAlarm() {
    // synchronized access since we might get a call from IdleThread
    final AlarmManager alarms = mAlarmManager;
    if (alarms != null) {
        ensureIdleAlarm();/*from  w w w  .j a  v  a 2 s  .co m*/
        alarms.cancel(mIdleIntent);
    }
}

From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java

private void stopService() {
    Log.e("Hitec telemetry", "Stopt service");
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}