如何在Flutter中创建服务以使应用始终在后台运行? [英] How to create a service in Flutter to make an app to run always in background?
问题描述
我想让Flutter应用程序始终在后台运行。使用android,我们必须创建一个始终在后台运行的服务。我没有在Flutter文档中找到有关服务的任何信息。
I would like to make my Flutter application to run always in background. With android, we have to create a Service that runs always in background. I don't find something about Services in the Flutter documentation.
是否可以用Flutter做这种事情?
Is it possible to do this kind of things with Flutter?
推荐答案
目前尚无法直接从颤抖的做到这一点,尽管有时可能会发生变化-请参见此错误/功能请求。不过,您确实有几个选择。
There isn't a way to do this directly from flutter right now although that may change at some point - see this bug/feature request. You do have a couple of options though.
第一个是使用 MethodChannels ,只需编写您想要创建后台服务的android代码(或者,如果您希望始终将其作为后台服务,则可以执行此操作而无需颤抖的通信)。
The first is to use MethodChannels and simply write the android code you want to create a background service (or if you want it to always be a background service you can probably do that without needing communication from the flutter side).
第二个是这两个插件的某种组合- android_alarm_manager 和 android_intent 。但这对所有用例都无济于事。
The second is some combination of these two plugins - android_alarm_manager and android_intent. But that won't help for all use-cases.
这篇关于如何在Flutter中创建服务以使应用始终在后台运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!