微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用户摇晃手机时如何唤醒应用程序

如何解决用户摇晃手机时如何唤醒应用程序

我在晃动手机时使用 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);
})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。