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:net.naonedbus.appwidget.HoraireWidgetProvider.java

/**
 * Programmer le rafraichissement des widgets.
 * //from   ww w. j  a  v  a 2  s. c  o  m
 * @param context
 * @param timestamp
 */
private synchronized void scheduleUpdate(final Context context, final long timestamp) {
    final long now = new DateTime().getMillis();
    final long triggerTimestamp = new DateTime(timestamp).plusMinutes(1).getMillis();

    if (sNextTimestamp < now || triggerTimestamp < sNextTimestamp) {
        sNextTimestamp = triggerTimestamp;

        final AlarmManager m = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        if (sPendingIntent != null) {
            m.cancel(sPendingIntent);

            if (DBG)
                Log.i(LOG_TAG,
                        Integer.toHexString(hashCode()) + " - " + "\tAnnulation de la prcdente alarme.");
        }

        final Intent intent = new Intent(ACTION_APPWIDGET_UPDATE);
        sPendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
        m.set(AlarmManager.RTC, sNextTimestamp, sPendingIntent);

        if (DBG)
            Log.i(LOG_TAG, Integer.toHexString(hashCode()) + " - " + "Programmation de l'alarme  : "
                    + new DateTime(sNextTimestamp).toString());
    }

}

From source file:pl.zajecia.cw3.MainService.java

/**
 * Stops current alarm, for when we stop service
 * and want to cancel all pending broadcasts.
 *//*from   w  w  w .  jav a 2 s  . c o  m*/
private void stopAlarm() {
    AlarmManager alarmM = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(INTENT_ALARM);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

    alarmM.cancel(pendingIntent);
}

From source file:com.remdo.app.MainActivity.java

private void disableNotificationsService() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pendingAlertsIntent);
    pendingAlertsIntent = null;/*from w  ww .  java  2 s  .  c o  m*/

    Intent i = new Intent(this, NotificationService.class);
    MainActivity.this.stopService(i);

}

From source file:com.remdo.app.MainActivity.java

private void disableGeopositioning() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pendingGeoIntent);
    pendingGeoIntent = null;//from w ww .ja  v a2s .c  o  m

    Intent i = new Intent(this, GeopositioningService.class);
    MainActivity.this.stopService(i);

    //Toast.makeText(this, getString(R.string.stopped_geo_service), Toast.LENGTH_LONG).show();
}

From source file:com.intel.RtcPingDownloadTester.java

public void clearAlarm() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
    Log.v(TAG, "clearAlarm");
    string_curr_state = "STOPED.";
    label_curr_state.setText(string_curr_state);
    return;/*from   www.  ja v  a  2  s  .  c o m*/
}

From source file:com.xperia64.cosi.CosiActivity.java

public void cancelAlarm() {
    Intent alarmIntent = null;/*from w  ww .j a  va  2  s  . c  o m*/
    PendingIntent pendingIntent = null;
    AlarmManager alarmManager = null;

    // OnCreate()
    alarmIntent = new Intent(this, NagReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), NagReceiver.REQUEST_CODE,
            alarmIntent, 0);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}

From source file:io.demiseq.jetreader.activities.MainActivity.java

private void setAlarmService() {
    if (!prefs.getBoolean("Alarm", false)) {
        Intent i = new Intent(this, FetchLatestService.class);
        PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.cancel(pi);
        String frequency = prefs.getString(GeneralSettingsActivity.KEY_UPDATE_FREQUENCY, "1440");
        int minute = Integer.parseInt(frequency);
        am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + minute * 60 * 1000, minute * 60 * 1000, pi);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("Alarm", true);
        editor.apply();//from www .ja  v a  2s.  c om
    }
}

From source file:com.achow101.bitcointalkforum.MainActivity.java

public void onResume() {
    super.onResume();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    int seconds = Integer.parseInt(prefs.getString("notifications_sync_freq", "60"));
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent i = new Intent(this, NotificationService.class);
    i.putExtra("SESSION ID", sessId);
    i.putExtra("Username", mUsername);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    am.cancel(pi);

    if (prefs.getBoolean("notifications_new_message", true)) {
        am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + seconds * 1000, seconds * 1000, pi);
    }//from  w w w .jav a2  s. c om
}

From source file:ca.ualberta.cs.drivr.MainActivity.java

private void setNotificationAlarm(Context context) {
    Log.d("ME", "Alarm setup");
    Intent intent = new Intent(getApplicationContext(), NotificationReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

    AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    am.cancel(pendingIntent);
    am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000, pendingIntent);
    Log.d("ME", "Alarm started");
}

From source file:com.kyleszombathy.sms_scheduler.Home.java

/**Cancels alarm given alarm service number
 * @param alarmNumb alarmNumber to delete*/
private void cancelAlarmInAndroidSystem(int alarmNumb) {
    Intent intent = new Intent(this, MessageAlarmReceiver.class);
    PendingIntent sender = PendingIntent.getBroadcast(this, alarmNumb, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.cancel(sender);
    Log.i(TAG, "cancelAlarmInAndroidSystem: Alarm number " + alarmNumb + " Canceled");
}