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).
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);
}
Permissions.RequestAsync
nothing is returned
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
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 馃槩
Most helpful comment
Did you add the
OnRequestPermissionsResultmember to the main activity?Have a quick look at https://docs.microsoft.com/en-us/xamarin/essentials/get-started?tabs=windows%2Candroid