Essentials: [Bug] No response from Permissions.RequestAsync<Permissions.ContactsRead>();

Created on 17 Apr 2020  路  3Comments  路  Source: xamarin/Essentials

Description

Hi there,

I think there is an issue when calling Permissions.RequestAsync()
I recently switched to using this and the first time i call it, i don't seem to get anything returned. The user is shown the permissions popup, but on allowing, nothing further seems to happen.

After the next call to the same function, the permission status is returned correctly (but doesn't need to show the popup this time, so must know in the backend that permission was granted).

Steps to Reproduce

This is the code i am using

        public async Task<bool> RequestAccessPhoneContacts()
        {
            PermissionStatus status = PermissionStatus.Denied;

            status = await MainThread.InvokeOnMainThreadAsync<PermissionStatus>(async () =>
            {
                return await Permissions.RequestAsync<Permissions.ContactsRead>();
            });

            return (status == PermissionStatus.Granted);
        }

Expected Behavior

Permissions.RequestAsync() should return PermissionStatus.Granted

Actual Behavior

nothing is returned

Basic Information

  • Version with issue: 1.5.2
  • IDE: VS 2019
  • Platform Target Frameworks:

    • Android: 9.0

I also placed an item on stackoverflow because i thought it may be a 'my code' issue.
https://stackoverflow.com/questions/61252633/how-do-i-request-permissions-when-not-on-the-ui-thread?noredirect=1#comment108384310_61252633

bug

Most helpful comment

Did you add the OnRequestPermissionsResult member to the main activity?

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults)
{
    Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

Have a quick look at https://docs.microsoft.com/en-us/xamarin/essentials/get-started?tabs=windows%2Candroid

All 3 comments

Did you add the OnRequestPermissionsResult member to the main activity?

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults)
{
    Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

Have a quick look at https://docs.microsoft.com/en-us/xamarin/essentials/get-started?tabs=windows%2Candroid

If I could rewind time 24 hours and read some documentation properly...

I'd just migrated over from https://github.com/jamesmontemagno/PermissionsPlugin and missed that change! Sorry for being a silly time waster :)

No prob! We all have lost 24 hours at one point or another... Sometimes lots of 24 hours 馃槩

Was this page helpful?
0 / 5 - 0 ratings