send Alarm Update Broadcast - Android Android OS

Android examples for Android OS:Alarm Broadcast

Description

send Alarm Update Broadcast

Demo Code


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

public class Main {
    private static String CODE = "intent_code";

    public static void sendUpdateBroadcast(Context context, int time,
            String code) {//from   w  ww . j a v  a2 s.com
        AlarmManager am = getAlarmManager(context);
        Intent i = new Intent(CODE);
        i.putExtra("code", code);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
                0, i, 0);
        am.set(AlarmManager.RTC, System.currentTimeMillis() + time * 1000,
                pendingIntent);
    }

    public static AlarmManager getAlarmManager(Context context) {
        return (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);
    }
}

Related Tutorials