Android Alarm Start start(Context context, Intent broadcastIntent, int requestCode, long delayAtMillis, long period)

Here you can find the source of start(Context context, Intent broadcastIntent, int requestCode, long delayAtMillis, long period)

Description

start

Declaration

@Deprecated
    public static void start(Context context, Intent broadcastIntent,
            int requestCode, long delayAtMillis, long period) 

Method Source Code

//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 {
    @Deprecated
    public static void start(Context context, Intent broadcastIntent,
            int requestCode, long delayAtMillis, long period) {
        PendingIntent sender = genPendingBroadcast(context, requestCode,
                broadcastIntent);/*from   w w  w.  ja  v a2  s . c  om*/
        long currentTime = SystemClock.elapsedRealtime();
        AlarmManager am = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);

        am.cancel(sender);
        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, currentTime
                + delayAtMillis, period, sender);
    }

    private static PendingIntent genPendingBroadcast(Context context,
            int requestCode, Intent broadcastIntent) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
                requestCode, broadcastIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        return pendingIntent;
    }

    public static void cancel(Context context, Intent broadcastIntent,
            int requestCode) {
        PendingIntent sender = genPendingBroadcast(context, requestCode,
                broadcastIntent);
        AlarmManager am = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);
        am.cancel(sender);
    }
}

Related

  1. startAlarm(Context context, int type, int index, int hour, int minute, String action)
  2. startAlarm(Context context, int type, int index, int interval, String action)
  3. startAlarmRing(Context c, String tone)
  4. startImmediately(Context context, Intent broadcastIntent, int requestCode, long period)