create Repeating Alarm - Android Android OS

Android examples for Android OS:Alarm Information

Description

create Repeating Alarm

Demo Code


//package com.java2s;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import android.util.Log;

public class Main {
    public static final String TEST_RECEIVER = "TestReceiver";
    private static final int REQUEST_CODE = 1000;

    public static void createAlarm(Context context) {
        Intent intent = new Intent("test_action");
        PendingIntent sender = PendingIntent.getBroadcast(context,
                REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        Log.v(TEST_RECEIVER, "sender:" + sender);

        AlarmManager am = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);
        //      am.cancel(sender);
        am.setRepeating(AlarmManager.RTC_WAKEUP,
                System.currentTimeMillis() + 100 * 1000, 30 * 1000, sender);
    }/*from  w ww  . j ava 2s. com*/
}

Related Tutorials