首页 > 解决方案 > Flutter background_location 不会在后台更新位置

问题描述

我已经安装了包“background_location”,并在我的屏幕(不是主屏幕)中调用了 initState 方法:

BackgroundLocation.setAndroidConfiguration(10000);
BackgroundLocation.startLocationService();

BackgroundLocation.getLocationUpdates((location) {
  updatePosition(location.latitude, location.longitude);
});

只要应用程序在前台,它就可以正常工作。一旦应用程序进入后台,大约 20 秒后,它会停止发送设备的位置,尽管已授予对位置的访问权限:“总是”。

我忘记了任何设置吗?

标签: androidflutter

解决方案


推荐阅读