Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To can check if location is enabled #14682

Closed
ComptonAlvaro opened this issue Apr 20, 2023 · 3 comments
Closed

To can check if location is enabled #14682

ComptonAlvaro opened this issue Apr 20, 2023 · 3 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info proposal/open

Comments

@ComptonAlvaro
Copy link

Description

I would like to know if location is enabled or not in an Android device.

My case is that if the user gives permissions to use the location, with the method GetLastKnownLocationAsync() I can get null if it is not possible to get the last location.

One reason could be that there is no GPS signal when the location is enabled.

And another reason could be because the location is disabled in the settings of the device.

I would like to know both cases, because in my case I would like to implment different logic in each case.

Is it possible to know if the location is disabled?

Thanks.

Public API Changes

Perhaps it could be possible a method like Location.IsEnabled() that returns a bool.

Intended Use-Case

bool isLocationEnabled = Location.IsEnabled();

if(isLocationEnabled == false)
{
    //Ask user to enabled it

    //if user tells no: do Action1();
   //else do nothing, wait user enables location and try again.
}
else
{
    //do Action2();
}
@Eilon Eilon added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Apr 20, 2023
@janseris
Copy link

janseris commented Apr 20, 2023

private CancellationTokenSource _gpsCheckCts;
try
{
    GeolocationRequest request = new GeolocationRequest(GeolocationAccuracy.Best, TimeSpan.FromSeconds(2));
    _gpsCheckCts = new CancellationTokenSource();
    Location location = await Geolocation.Default.GetLocationAsync(request, _gpsCheckCts.Token);
}
catch (FeatureNotEnabledException)
{
    Debug.WriteLine("GPS is not enabled. Please turn on GPS.)";
}

@jfversluis
Copy link
Member

The Permissions API should also take into account if something is possible/available or not: https://learn.microsoft.com/dotnet/maui/platform-integration/appmodel/permissions

So I'd say this is already possible to determine.

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Apr 21, 2023
@janseris
Copy link

janseris commented Apr 21, 2023

The Permissions API should also take into account if something is possible/available or not: https://learn.microsoft.com/dotnet/maui/platform-integration/appmodel/permissions

So I'd say this is already possible to determine.

GPS permission granted/not granted is different than enabled/disabled GPS

@ghost ghost locked as resolved and limited conversation to collaborators May 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info proposal/open
Projects
None yet
Development

No branches or pull requests

4 participants