Flutter:在未使用时收听位置更新,即使在使用应用程序时设置了位置权限

问题描述 投票:0回答:1

如果这个问题重复,我很抱歉,但相信我,颤振中的问题

How to listen to current location changes while the app is minimized and location permission is set to while using the app
没有确定的答案。

有同样的问题但没有给出解决方案 使用 GeoLocator 在后台获取当前位置

不知道

lyft
Uber
等其他大公司是如何处理这个问题的?

我构建了一个驱动程序应用程序,需要共享驱动程序当前位置,当应用程序正在使用(未最小化)时它可以完美运行,但当用户打开另一个应用程序(我的应用程序进入后台)时,位置更新就会停止。

我曾经让司机将其位置权限设置为

always
并推送到生产环境,但司机不同意让他们的位置一直被访问。

我使用的软件包

location
permission_handler

我的代码中有一部分可以监听 lcoation 的更改

 _listenLocationChanges(address, orderId) async {
    _locSubscription = location.onLocationChanged.listen((newLocationData) {
      print("listenning to location changes...........");
      print(newLocationData);
}

当然,我在访问该位置之前运行了

location.enableBackgroundMode(enable: true);
,并向 android manifist 添加了以下权限

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />

任何帮助表示赞赏。

flutter google-maps location driver tracking
1个回答
0
投票

在现代手机中,操作系统会终止后台任务以优化电池。我认为在应用程序未使用时没有可能跟踪位置的方法。对于在后台运行的连续任务,还需要完成某些其他操作,请访问https://dontkillmyapp.com/了解此类补救措施

© www.soinside.com 2019 - 2024. All rights reserved.