How to schedule an alarm on specific time in Flutter?

拜拜、爱过 提交于 2021-01-05 06:18:04

问题


In my Flutter project, I want to schedule an alarm on a specific time of a day or just trigger the built in alarm in my phone on that particular time.

For that purpose, I have integrated one plugin from Flutter -

https://pub.dev/packages/android_alarm_manager#-example-tab-

And then I followed exactly the example given in that documentation and added all the permissions in Android Manifest file.

After running this project it shows like below-

It is showing one button to shot one alarm but it is just updating the text. Nothing like any alarm is set as I wanted and I am not getting what's going on in this project.

So, I need a solution that- what changes I need to do get that alarm working on a fixed time scheduled by me and it should work from background as I want this alarm to work when I remove it from memory too. Any example code sample, full documentation or project sample will be helpful for this question.


回答1:


You need to use some things together. You need to run a background process and start to play a sound from there. I suggest you to take a deep look at the flutter docs about the subject:
https://flutter.dev/docs/development/packages-and-plugins/background-processes

Here are some useful packages that might help:

  • To run background processes continuously, take a look at this package:
    https://pub.dev/packages/background_fetch

  • To play a sound from background processes:
    https://flutter.dev/docs/development/packages-and-plugins/background-processes

  • If you need to show scheduled messages, use local notifications:
    https://pub.dev/packages/flutter_local_notifications



来源:https://stackoverflow.com/questions/61445647/how-to-schedule-an-alarm-on-specific-time-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!