Skip to content

Instantly share code, notes, and snippets.

@andigu
Last active February 26, 2023 18:01
Show Gist options
  • Save andigu/f431de4de8fa72c5e070b9b55f4645b8 to your computer and use it in GitHub Desktop.
Save andigu/f431de4de8fa72c5e070b9b55f4645b8 to your computer and use it in GitHub Desktop.
public class Alarm extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
final Intent service = new Intent(context, AlarmService.class);
HeadlessJsTaskService.acquireWakeLockNow(context);
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
context.startService(service);
}
});
}
public void setAlarm(final Context context) {
if (System.currentTimeMillis() - AlarmService.lastActive >= 2 * 60 * 1000) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
am.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), 1000 * 60, pi);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment