cancel Alarm - Android Android OS

Android examples for Android OS:Alarm Cancel

Description

cancel Alarm

Demo Code

/**/*from   w w  w . j  av a 2  s. co m*/
 * Copyright (C) 2012 SINTEF <fabien@fleurey.com>
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3, 29 June 2007;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class Main{
    private static final int ACTIVE_NOTIFICATION_ID = 79290;
    protected static void cancelAlarm(Context context) {
        Intent startService = new Intent(context,
                BatteryLoggerService.class);
        PendingIntent pendingIntent = PendingIntent.getService(context, 0,
                startService, PendingIntent.FLAG_CANCEL_CURRENT);
        ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE))
                .cancel(pendingIntent);

        ((NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE))
                .cancel(ACTIVE_NOTIFICATION_ID);
    }
}

Related Tutorials