3

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?

J. S.
  • 8,905
  • 2
  • 34
  • 44
  • The 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). – William Gatto Filho Jan 22 '20 at 13:38
  • Please specify your problem and give a minimal reproducible example. – Ling Vu Jan 22 '20 at 15:31
  • Hey 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 – William Gatto Filho Jan 23 '20 at 14:47

1 Answers1

2

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

Edgarsz
  • 110
  • 1
  • 6