cancel Alarm using AlarmManager - Android Android OS

Android examples for Android OS:Alarm Cancel

Description

cancel Alarm using AlarmManager

Demo Code


import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import java.util.Calendar;

public class Main{
    public static void cancelAlarm(Context context, int num) {
        AlarmManager alarmMgr;/*from   w  w w.  ja  v  a  2s.  c  om*/
        PendingIntent alarmIntent;
        Intent intent = new Intent(context, AlarmReceiver.class);
        alarmIntent = PendingIntent.getBroadcast(context, num, intent, 0);
        alarmMgr = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);
        if (alarmMgr != null) {
            alarmMgr.cancel(alarmIntent);
        }

    }
}

Related Tutorials