Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

[Bug] Can't distinguish between Location turned OFF or if device doesn't have hardware to support it #2034

Open
otvns opened this issue Aug 11, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@otvns
Copy link

otvns commented Aug 11, 2022

Hi all,

I'm facing a super odd scenario when trying to check if the user has the phone Location ON.

Context:
My app is communicating with a Bluetooth device using a BLE protocol.
For some Android versions (e.g. 9 or 10), in order to use the Bluetooth, we also need to ask for location permissions and have the location turned on in our device. Otherwise, if we perform a scan nothing is found and no exceptions are fired.

Workaround:
So far, one of the solutions trying to check if the location is ON and if not we can move the users to the settings section where they can turn it on manually.
To check the Location status we're using the following code (suggested in several forums/blogs and even in some issues reported here):

var locationManager = (LocationManager)Application.Context.GetSystemService(Context.LocationService);
var status =  locationManager.IsProviderEnabled(LocationManager.GpsProvider);

Problem:
This code works perfectly for most of the devices but, the ones without GPS antenna will always return 'false' when evaluating if the provider is enabled and even if the user has the value turned ON on device settings.
In one hand I understand why we are getting the 'false' value but, in the other hand, we really have the location turned ON and we could have a 'true' result due to that.
As a side note, if the location still needs to be turned ON on these devices without GPS antenna to scan BT devices properly.

Question:
Is there any workaround so we can check if the device has the hardware and the location settings option turned ON?
Because it seems that we need to distinguish these two situations.

Thanks.

  • Version with issue: Xamarin Essentials 1.7.3
  • Platform Target Frameworks:
    • Android:
      -- Minimum version: Android 6.0 (API Level 23)
      -- Target version: Android 12.0 (API Level 31)
  • Affected Devices:Zebra TC52
@otvns otvns added the bug Something isn't working label Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant