【问题标题】:How to awake the app when user shake the mobile phone in flutter当用户颤抖手机时如何唤醒应用程序
【发布时间】:2021-09-09 01:07:29
【问题描述】:
【问题讨论】:
标签:
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);
})