Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

RequestPermission always returns Granted #178

Open
programmingworld1 opened this issue May 19, 2020 · 0 comments
Open

RequestPermission always returns Granted #178

programmingworld1 opened this issue May 19, 2020 · 0 comments

Comments

@programmingworld1
Copy link

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

RequestPermission on Xamarin.Forms always returns Granted.

Version Number of Plugin: xamarin.essentials 1.3.1
Device Tested On: Android A-70
Simulator Tested On: None
Version of VS: 16.5.4
Version of Xamarin: 4.5.0.617
Versions of other things you are using:

Steps to reproduce the Behavior

Ask for location permission and you will always get granted

Expected Behavior

When I ask for location permission, it should be not granted because no permission has been granted

Actual Behavior

Permission always returns granted

Code snippet

`
if (!_crossGeolocatorService.IsSupported() || _crossGeolocatorService.IsListening())
{
return;
}

        if (!_crossGeolocatorService.IsGeolocationAvailable())
        {
            _userDialogs.Alert("Geolocation is not available on this device!");
            return;
        }

        var status = await CrossPermissions.Current.CheckPermissionStatusAsync<LocationPermission>();
        if (status != PermissionStatus.Granted)
        {
            if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
            {
                await _userDialogs.AlertAsync("Please enable your location!");
            }

            status = await CrossPermissions.Current.RequestPermissionAsync<LocationPermission>();
        }

        if(status == PermissionStatus.Granted)
        {

            CrossGeolocator.Current.DesiredAccuracy = 1;
            CrossGeolocator.Current.PositionChanged += PositionChanged;

            var result = await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(5), 1, false, new ListenerSettings
            {
                ActivityType = Plugin.Geolocator.Abstractions.ActivityType.Other,
                AllowBackgroundUpdates = true,
                DeferLocationUpdates = false,
                DeferralDistanceMeters = 1,
                DeferralTime = TimeSpan.FromSeconds(1),
                ListenForSignificantChanges = false,
                PauseLocationUpdatesAutomatically = false
            });
        }`

Screenshots

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant