问题描述
我在晃动手机时使用 CallKeep 唤醒应用程序(为了检测晃动,我使用 Shake plugin),我想在用户晃动手机并且应用程序被杀死时启动颤动应用程序。
我知道我可以使用 background_fetch: ^1.0.0,但问题是它只允许每 15 分钟后使用,我想一直收听抖动事件。
请帮帮我,我被困在这里了。
提前致谢
解决方法
仔细检查代码片段和 API 文档。 configure 中有一个名为 minimumFetchInterval 的属性。您可以调整值并检查它是否有效,应该有效。
api-doc 以下代码片段位于 api 文档中的 Android 部分下。
BackgroundFetch.configure(BackgroundFetchConfig(
minimumFetchInterval: 15,// <-- minutes
stopOnTerminate: false,startOnBoot: true
),(String taskId) async { // <-- Event callback
// This callback is typically fired every 15 minutes while in the background.
print('[BackgroundFetch] Event received.');
// IMPORTANT: You must signal completion of your fetch task or the OS could
// punish your app for spending much time in the background.
BackgroundFetch.finish(taskId);
},(String taskId) async { // <-- Task timeout callback
// This task has exceeded its allowed running-time. You must stop what you're doing and immediately .finish(taskId)
BackgroundFetch.finish(taskId);
})