I'm trying to resolve a crash when my application ask for permission to connect to a detected device.
I'm handling in the Android part using the usbManager.
It appears the the RequestPermission() from the usbManager does not wait for user input, so App continue exécution and crash.
After restart if permission was given everything works fine.
At first I added a broadcast receiver in the android interface to handle the event, but the Xamarin.forms part is not award that the process is async.
So I started to add Xamarin.Essential support like shown in the Xamarin doc.
I did add the code for Activity startup to init Xamarin Essential and the overrided function :
protected override void OnCreate(Bundle savedInstanceState)
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);
I then create a Platform interface as advised in the Xamarin Guide. In that function a call the platform interface the request permission.
async Task<PermissionStatus> IUsbPermissions.RequestAsync()
status = await _iusbManager.RequestPermAsync(_szDevName);
The problem is that the request permission just call the usbmanager request, so that I never fall in the override function : OnRequestPermissionsResult().
How can make it wait for the permission event ?
Does the fact that I define a custom permission interface disable the override OnRequestPermissionsResult() ?