How to automatically awake the application in flutter?
1,369
You can use android_alarm_maganer to achive what you need. Simply run it every second or so and check if DateTime.now() meets your criteria.
Example:
import 'package:android_alarm_manager/android_alarm_manager.dart';
void checkAlarms() {
if(DateTime().now == alarm){
//Do something
}
}
main() async {
final int helloAlarmID = 0;
await AndroidAlarmManager.initialize();
runApp(...);
await AndroidAlarmManager.periodic(const Duration(seconds: 1), helloAlarmID, checkAlarms);
}
Then you can run another Activity as described here
Author by
William Gatto Filho
Updated on December 01, 2022Comments
-
William Gatto Filho over 1 year
I am coding an alarm on my own and I would like that the alarm would wake up the phone and show the Alert Dialog. Can someone give me some insight on how to do this please?
-
William Gatto Filho over 4 yearsThe alert, inputs, and everything else is ok. I only need to wake the phone at a desired time(this time is on me and is ok too).
-
Ling Vu over 4 yearsPlease specify your problem and give a minimal reproducible example.
-
William Gatto Filho over 4 yearsHey Ling...sorry but I can't...but It works like this I have an alarm time set by someone and it must show an Alert dialog when the time is come. I can't find something to run in the background till timeNow and alarm time aer the same and wake the screen with the alert and its functions
-