Android Xamarin后台服务-每x分钟获取GPS位置? [英] Android Xamarin Background service - Get GPS Location every x minutes?

查看:237
本文介绍了Android Xamarin后台服务-每x分钟获取GPS位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamarin开发应用程序,并且我需要一个后台服务,该服务可以定期(例如每15分钟一次)获取用户的GPS位置.

I'm developing an app using Xamarin, and I need a background service that gets the user's GPS location at recurring intervals (say, every 15 minutes).

此项目( https://github.com/xamarin/mobile- samples/tree/master/BackgroundLocationDemo )是我能找到的最接近示例代码的位置,它声称即使在后台运行该应用程序,该位置也会继续更新.开箱即用,似乎并非如此.

This project (https://github.com/xamarin/mobile-samples/tree/master/BackgroundLocationDemo) is the closest I can find to example code, and it claims that the location continues to update, even with the app in the background. Out of the box, this doesn't seem to be the case.

以下是应用程序移至后台后的日志,然后它将停止更新GPS.我只想知道这是否是正常行为,如项目说明所述.

Here's the log once the application moves into the background, and then it stops updating GPS. I'd just like to know if this is normal behaviour or not, as the project description says otherwise.

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

一旦发生应用程序事件:停止",该应用程序将进入后台并且GPS服务不再起作用.另外,我使用的是Android 8.0-不确定是否与此有关.

As soon as "App Event: stop" happens, the app moves into the background and the GPS Service no longer functions. Also, I use Android 8.0 - not sure if that has anything to do with it or not.

任何人都可以提供真知灼见(甚至更好的示例代码/项目),向我指出正确的方向吗?

Could anyone offer insight (or even better, example code/projects) to point me in the right direction?

推荐答案

由于@SushiHangover,我创建了前台服务.现在效果很好.

I created a Foreground Service, thanks to @SushiHangover. It works very well now.

这篇关于Android Xamarin后台服务-每x分钟获取GPS位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆