Last active
February 26, 2023 18:01
-
-
Save andigu/f431de4de8fa72c5e070b9b55f4645b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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