Android examples for Android OS:Alarm Broadcast
add Alarm Broadcast
//package com.java2s; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.SystemClock; public class Main { public static void addAlarmBroadcast(Context context, long intervalTime, String action) { AlarmManager alarmManager = (AlarmManager) context .getApplicationContext().getSystemService( Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(action), PendingIntent.FLAG_UPDATE_CURRENT); long triggerTime = SystemClock.elapsedRealtime();// + intervalTime; alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, triggerTime, intervalTime, pendingIntent); }/*from www .j av a2 s . c o m*/ }