android / location-samples

Multiple samples showing the best practices in location APIs on Android.
Apache License 2.0
2.71k stars 2.78k forks source link

Always RESULT_CANCELED called in Samsung&One plus device for Location Settings Dialog (Android 8.0.0 ) #193

Open rameshkec85 opened 5 years ago

rameshkec85 commented 5 years ago

I have implemented Location settings popup to set High Accuracy. But it always toggles between Battery Saving mode and Phone Only mode, not set to High Accuracy mode forever. \

Device : Samsung Galaxy S9,One plus 3T OS: 8.0.0

iqbalprabu commented 5 years ago

anyone help this issue ? i also get this issue on my devices

talhahasanzia commented 5 years ago

Having same issue, also reported on stack overflow as, https://stackoverflow.com/q/55550481/4856761

Reproduced on Redmi 4X Nougat and Droid Turbo Marshmallow

Anyone who got the solution? Why this official sample is having problems? Anyone?

Ledarath commented 5 years ago

Hello guys,

We faced the same issue this week and here are our conclusions on this subject :

There is a problem with the Google popup from ResolvableApiException called by this :

final int REQUEST_CHECK_SETTINGS = 1026;
ResolvableApiException resolvable = (ResolvableApiException) exception;
resolvable.startResolutionForResult(this, REQUEST_CHECK_SETTINGS);

So, before Android 9.0 Pie there were 3 levels of localisation accuracy that the user can define in his own settings of the device :

In the case that you need PRIORITY_HIGH_ACCURACY settings:

It seems fixed on Android 9.0 since the modes were deleted from the settings and the system handle everything correctly.

The main issue is that the Google popup can't switch to HIGH accuracy mode when location is ON. Even worse, if you ask PRIORITY_BALANCED_POWER_ACCURACY for instance and the location service is OFF, the popup will turn on the location service in the ONLY GPS mode even if the user did select HIGH_ACCURACY previously. In this case if other apps ask for PRIORITY_HIGH_ACCURACY it will fail. Only the user can switch on the HIGH accuracy mode again in the settings.

That's why we don't use this popup on Android < 9.0 Pie instead, we ask the user to turn ON the HIGH accuracy mode by himself.

I don't know if it can be fix otherwise, if someone has another workaround please let me know.