BirjuVachhani / locus-android

An Awesome Kotlin Location library to retrieve location merely in 3 lines of code
https://birju.dev/posts/retrieve-location-in-just-3-lines-android/
Apache License 2.0
358 stars 40 forks source link

location_settings_denied returned while enabling the location. #46

Closed kosratdev closed 3 years ago

kosratdev commented 3 years ago

Describe the bug When the device's location is turned off then the app requests to enable location after you enable it, it will return location_settings_denied

To Reproduce Steps to reproduce the behavior:

  1. Turn off your locatoin.
  2. Go to your app that uses this library.
  3. Request to get Locus.getCurrentLocation
  4. Enable location
  5. See error

Expected behavior After enabling the location should retry to get the location instead returning location_settings_denied

Smartphone (please complete the following information):

BirjuVachhani commented 3 years ago

@kosratdev It is supposed to retrieve location updates. location_settings_denied is thrown if it could verify that the location is enabled.

kosratdev commented 3 years ago

@BirjuVachhani The library requests to open the device's location when enabled from the library dialog it returns location_settings_denied

BirjuVachhani commented 3 years ago

@kosratdev That's correct but it should only return that if something is not right. Could you please verify this on Android devices other than Samsung because I tried to replicate the same on the emulator but it worked fine. Maybe that will be helpful to narrow down the issue to specific devices/OS.

kosratdev commented 3 years ago

Just I have checked it, it works for the emulator but on my Samsung device doesn't work I don't know why. I will try to test it on another physical device

BirjuVachhani commented 3 years ago

@kosratdev I thought that might be the case. I do not own any Samsung devices but I would love to get some more info on this. Maybe you could share the stacktrace/logs for this from the Samsung device? Also, there might be chances that this may work just fine for some Samsung devices. So if you have any other around, please test on them as well.

Damercy commented 3 years ago

Hey, I'm facing the same issue as well. When I use getCurrentLocation() and have my location turned off, it requests for turning on the location as expected, however, once I do turn on the location, it fails with exception in log com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED i.e. It is unable to resolve that I have actually granted the location & hence start getting the current location. Ideally, once I turn on the location, it should proceed forward with giving me the current location automatically instead of throwing above exception. Testing device is a Lenovo K10 Note running Android Pie.

Any help is appreciated! 😄

BirjuVachhani commented 3 years ago

This seems weird. Everything seems to be working fine when I test it on an emulator. Will try to check with a real device.

iballan commented 3 years ago

Any update about this issue ?

BirjuVachhani commented 3 years ago

I tested it on Samsung S20 (Android 11) on Browser stack and it seems to be working fine. Can anyone provide me a video or anything like that?

ankush-dhiman commented 3 years ago

I was facing same issue, So I made some changes in library. Now It is working fine for me. Tested (Eabled/Disabled GPS and Handled it based on resultCode.

  override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_CODE_LOCATION_SETTINGS) {
            if (resultCode == RESULT_OK) {
                shouldProceedForLocation()
            }
            else {
                checkSettings(success = { shouldProceedForLocation() }) {
                    postResult(Constants.LOCATION_SETTINGS_DENIED)
                }
            }
BirjuVachhani commented 3 years ago

I was facing same issue, So I made some changes in library. Now It is working fine for me. Tested (Eabled/Disabled GPS and Handled it based on resultCode.

  override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_CODE_LOCATION_SETTINGS) {
            if (resultCode == RESULT_OK) {
                shouldProceedForLocation()
            }
            else {
                checkSettings(success = { shouldProceedForLocation() }) {
                    postResult(Constants.LOCATION_SETTINGS_DENIED)
                }
            }

If this is working for everyone then I'll make required changes and publish a new version.

BirjuVachhani commented 3 years ago

Can anyone check on this dependency this and confirm here? I have applied @ankush-dhiman's solution on this. If this works then I'll release a version.

implementation 'com.github.BirjuVachhani:locus-android:master-SNAPSHOT'
BirjuVachhani commented 3 years ago

@kosratdev Did you get a chance to check this?

9und70 commented 3 years ago

Can anyone check on this dependency this and confirm here? I have applied @ankush-dhiman's solution on this. If this works then I'll release a version.

implementation 'com.github.BirjuVachhani:locus-android:master-SNAPSHOT'

It works on a Samsung Galaxy Tab A SM-T510

BirjuVachhani commented 3 years ago

@9und70 Great. I'll release a fix for this soon. Thanks!