简体   繁体   English

当应用程序在Pie设备的后台和前台时获取位置的最佳代码

[英]A best code for getting location when app is in background and foreground for Pie devices

I know here is a good example of background services to get location. 我知道是后台服务获取位置的一个很好的例子。 But in that code I am unable to understand that which one service is best of getting location and how to get location on another activity from service. 但是在该代码中,我无法理解哪个服务最适合获取位置以及如何从服务获取另一个活动的位置。 I also know i have to call start service in another activity and i have to write broadcast function for getting location periodically. 我也知道我必须在另一项活动中致电启动服务,并且必须编写广播功能以定期获取位置。

Now my main problem is I only know all of that what I have to do but here I am unable how to do . 现在我的主要问题是我只知道我必须做的所有事情,但是在这里我无法做。

I want a specific code help where I have a service for location and get that location on another activity when app is in background or foreground with less battery drag for Pie Devices. 我需要特定的代码帮助,在其中我可以提供位置服务,并且当应用程序在后台或前景中运行时,在其他活动中获得该位置,而对Pie Devices的电池拖动较少

After two months of searching I found a best code which works on Oreo and above devices when app is in foreground or background. 经过两个月的搜索,当应用程序处于前台或后台时,我发现了一个适用于Oreo及以上设备的最佳代码。

So I make a repository for all developer to take that code and use. 因此,我为所有开发人员创建了一个存储库,以使用和使用该代码。 Code link 代码链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当应用程序在Android Pie上受后台限制时启动前台服务 - Starting a foreground service when an app is background restricted on Android Pie 当应用程序移至后台时,在前台服务中获取位置更新不起作用 - getting location updates in foreground service isn't working when app is moved to background 在前台更改活动时在后台获取位置 - Getting a location in background while activity is changed in the foreground 如何检测 android 应用程序何时在后台和前台处理一些代码 - how to detect when android app in background and foreground to handle some code 如何将App背景上的GPS位置更新为前景? - How to update GPS Location on App Background to Foreground? Xamarin Forms Android Pie 在应用程序后台睡眠模式下无法获取当前位置 - Xamarin Forms Android Pie Not Getting Current Location in App Background Sleep Mode 确定应用何时为前台的最佳方法 - Best way to determine when app is foreground 获取位置会同时更新Android Google Maps中的前景和背景 - Getting location updates both foreground and background in android google maps 仅在前台应用:如何避免“未声明后台位置访问” - App only in foreground: How to avoid “Background location access not declared” 从后台删除应用程序时也无法获取位置更新 - Not getting location updates when App is removed from background also
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM