【问题标题】:How to awake the app when user shake the mobile phone in flutter当用户颤抖手机时如何唤醒应用程序
【发布时间】:2021-09-09 01:07:29
【问题描述】:

我在摇动手机时使用CallKeep 来唤醒应用程序(我使用Shake plugin 来唤醒应用程序),当用户摇动手机并且应用程序被杀死时,我想启动颤动应用程序。

我知道我可以使用background_fetch: ^1.0.0,但问题是它只允许每 15 分钟后,我想一直收听抖动事件。

请帮帮我,我被困在这里了。

提前致谢

【问题讨论】:

    标签: android ios flutter dart background-fetch


    【解决方案1】:

    仔细检查代码 sn-p 和 API 文档。 configure 里面有一个属性叫 minimumFetchInterval。您可以调整该值并检查它是否有效,应该有效。

    api-doc以下代码sn-p放在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);
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多