delight-im / Android-SimpleLocation

Utility class for easy access to the device location on Android
Apache License 2.0
200 stars 75 forks source link

Not working in Android 10 real device #37

Closed okynk closed 4 years ago

okynk commented 4 years ago

Hi, I implemented everything according to the docs, but it's not working in Google Pixel 3 real device (not emulator)

I've checked :

If I compile the same code to API 29 Emulator, everything working well. The device's GPS sensor is not broken, because any other maps apps are still working fine.

Do you have any idea, what I need to check or fix?

ocram commented 4 years ago

Thanks for your excellent description of the problem and what you have done!

So you’re saying it doesn’t work on a Pixel 3 with Android 10, but it does work on an emulator with Android 10, right? (Since API level 29 is Android 10, isn’t it?)

First, could you try using a longer interval, such as 1000 * 15 (15 seconds) and see if that changes anything? You definitely don’t need to wait for 5 minutes then. A location update should be available within a minute.

Second, does it make any difference whether you are outside (perhaps with a clear view of the sky) or inside (a larger building)? Other apps could be relying on Wi-Fi location here while you are explicitly requesting a GPS location with the constructor arguments.

Third, are you running the app in the foreground or in the background while testing this? At least with Android 10, this really makes a difference. You may even have to request the android.permission.ACCESS_BACKGROUND_LOCATION permission if running in the background.

okynk commented 4 years ago

@ocram Thank you for your help! Your second statement solved the issue. After I changed the requireFine to false, it could get the lat & long.

Because I want to get the most accurate location of the user, is it possible to get the "fine" location with automatic fallback to "coarse" location if can't get the "fine" location (or if get 0.0/0.0)?

ocram commented 4 years ago

That’s great to hear, thanks!

Currently, you can only use the “coarse” location with a fallback to the “fine” location, i.e. the other way round – in case the “coarse” location is not available.

The reason is that, when you want “fine” location, you usually want a guarantee that what you’re getting really has the accuracy you need. For example, if you’re working on turn-by-turn navigation, you rather want “no location available” than a location that is actually only Wi-Fi location and is of no real value to the use case at hand.