Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Xamarin Essentials Permissions failing to grant permission

$
0
0

I'm currently writing a Xamarin Forms app which requires use of the camera, in the code below I am requesting the permission using the Xamarin Essentials Permissions which comes back as "Granted"; immediately following that I am requesting use of the camera to take a photo, which throws the following error.

ex = {Plugin.Media.Abstractions.MediaPermissionException: Camera permission(s) are required.

The permission code

public static async Task<bool> GetPermission<TPermission>() where TPermission : BasePermission, new()
    {
        var hasPermission = await Permissions.CheckStatusAsync<TPermission>();

        if (hasPermission == PermissionStatus.Granted)
            return true;
        else if (hasPermission == PermissionStatus.Disabled)
            return false;

        var result = await Permissions.RequestAsync<TPermission>();
        if (result != PermissionStatus.Granted)
            return false;

        return true;
    }

The photo manager code

if(!await PermissionHelpers.GetPermission<Permissions.Camera>())
        {
            await new ErrorAlert().Show("App can't take a picture without permission to use the camera");
            return string.Empty;
        }

        var photo = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
        {
            PhotoSize = PhotoSize.Small,
            SaveToAlbum = false
        });

As previously said, the GetPermission method returns true, but still the error is thrown.

I'm currently running this on Android.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>