Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

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

Open otvns opened this issue 3 years ago • 0 comments

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 avatar Aug 11 '22 16:08 otvns