Skip to content

Instantly share code, notes, and snippets.

@yccheok
Last active August 22, 2017 19:29
Show Gist options
  • Select an option

  • Save yccheok/d39b434470a4135104efae76ec75afc2 to your computer and use it in GitHub Desktop.

Select an option

Save yccheok/d39b434470a4135104efae76ec75afc2 to your computer and use it in GitHub Desktop.
public static void startAlarmBroadcastReceiver(Context context, long delay) {
Intent _intent = new Intent(context, AlarmBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, _intent, 0);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
// Remove any previous pending intent.
alarmManager.cancel(pendingIntent);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + delay, pendingIntent);
}
public class AlarmBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment