Android Xamarin 后台服务 - 每 x 分钟获取一次 GPS 位置?
Android Xamarin Background service - Get GPS Location every x minutes?
我正在使用 Xamarin 开发一个应用程序,我需要一个后台服务来定期获取用户的 GPS 位置(例如,每 15 分钟)。
这个项目 (https://github.com/xamarin/mobile-samples/tree/master/BackgroundLocationDemo) 是我能找到的最接近示例代码的项目,它声称该位置会继续更新,即使应用程序在后台运行也是如此。开箱即用,好像不是这样。
这是应用程序进入后台后停止更新 GPS 的日志。我只想知道这是否是正常行为,正如项目描述中所说的那样。
12-12 08:19:12.324 D/MainActivity(10254): Foreground updating
12-12 08:19:12.345 D/LocationService(10254): Latitude is -44.40749468
12-12 08:19:12.345 D/LocationService(10254): Longitude is 171.25077323
12-12 08:19:12.345 D/LocationService(10254): Altitude is 4
12-12 08:19:12.346 D/LocationService(10254): Speed is 2.37
12-12 08:19:12.346 D/LocationService(10254): Accuracy is 39.664
12-12 08:19:12.346 D/LocationService(10254): Bearing is 350.9
12-12 08:19:12.348 D/MainActivity(10254): Location status changed, event raised
12-12 08:19:12.917 D/AppTracker(10254): App Event: stop
12-12 08:19:12.931 D/MainActivity(10254): OnPause: Location app is moving to background
一旦 "App Event: stop" 发生,应用程序就会进入后台,GPS 服务将不再运行。另外,我使用 Android 8.0 - 不确定这是否与此有关。
任何人都可以提供见解(或者更好,例如 code/projects)来为我指明正确的方向吗?
感谢@SushiHangover,我创建了一个前台服务。现在效果很好。
我正在使用 Xamarin 开发一个应用程序,我需要一个后台服务来定期获取用户的 GPS 位置(例如,每 15 分钟)。
这个项目 (https://github.com/xamarin/mobile-samples/tree/master/BackgroundLocationDemo) 是我能找到的最接近示例代码的项目,它声称该位置会继续更新,即使应用程序在后台运行也是如此。开箱即用,好像不是这样。
这是应用程序进入后台后停止更新 GPS 的日志。我只想知道这是否是正常行为,正如项目描述中所说的那样。
12-12 08:19:12.324 D/MainActivity(10254): Foreground updating
12-12 08:19:12.345 D/LocationService(10254): Latitude is -44.40749468
12-12 08:19:12.345 D/LocationService(10254): Longitude is 171.25077323
12-12 08:19:12.345 D/LocationService(10254): Altitude is 4
12-12 08:19:12.346 D/LocationService(10254): Speed is 2.37
12-12 08:19:12.346 D/LocationService(10254): Accuracy is 39.664
12-12 08:19:12.346 D/LocationService(10254): Bearing is 350.9
12-12 08:19:12.348 D/MainActivity(10254): Location status changed, event raised
12-12 08:19:12.917 D/AppTracker(10254): App Event: stop
12-12 08:19:12.931 D/MainActivity(10254): OnPause: Location app is moving to background
一旦 "App Event: stop" 发生,应用程序就会进入后台,GPS 服务将不再运行。另外,我使用 Android 8.0 - 不确定这是否与此有关。
任何人都可以提供见解(或者更好,例如 code/projects)来为我指明正确的方向吗?
感谢@SushiHangover,我创建了一个前台服务。现在效果很好。