Code example for WakefulBroadcastReceiver

1
import android.content.Context; 
import android.content.Intent; 
import android.os.SystemClock; 
import android.support.v4.content.WakefulBroadcastReceiver; 
 
public class PollReceiver extends WakefulBroadcastReceiver { 
  private static final int PERIOD=900000; // 15 minutes
  private static final int INITIAL_DELAY=5000; // 5 seconds
 
  @Override 
  public void onReceive(Context ctxt, Intent i) {
    if (i.getAction() == null) {
      startWakefulService(ctxt,
                          new Intent(ctxt, ScheduledService.class));
    } 
    else { 
      scheduleAlarms(ctxt);
    } 
  } 
 
  static void scheduleAlarms(Context ctxt) {