Fused Location Provider not getting location unless GPS is on

拟墨画扇 提交于 2019-12-03 05:39:03

I had the same issue like you, which is not an issue at all. Android used to have a GPS button that let you control it directly, but they replaced it with a Location button which works different. In order to get any type of location, you must turn it on. Like you, I thought the Location button turns on and off the GPS only, but that's not the case. You can control the GPS by changing the location mode: 1. High accuracy (GPS, Wi-Fi and mobile networks) 2. Power Saving (Wi-Fi and mobile networks) 3. GPS only

I think I have found the solution of the problem.

If you go to Settings -> Privacy and Safety -> Location, you would notice that Location is not only GPS, but it actually lets user decide which providers can be used. For example, you can set that only WiFi and Cellular should be used to obtain any locations

Disabling Location option will disable all providers at once, not only GPS.

To test that app for users with only WiFi can get a location – change setting to "Wifi+Cellular".

you seem to be using LocationRequest.PRIORITY_HIGH_ACCURACY, which prefers using GPS above and over other methods. You might want to use PRIORITY_BALANCED_POWER_ACCURACY, which will use WiFi and cell towers before using GPS.

Also, since PRIORITY_BALANCED_POWER_ACCURACY is a "coarse" level of accuracy, you might want to change the location permission in your manifest appropriately.

The training documentation details more information about the priority flags, you might also want to go through it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!