Uno-Platform permission problems for android development

Viewed 247

I am new to the Uno-Plaform development scene and i wanted to create my own speech recognition.

The setup of my speech recognition works with cortana and UWP, but the setup for my android phone has been creating some problems.

I have added these lines of code to my Android manifest:

AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

With these lines of code i should technically be able to record my audio coming from my phone.

System.Exception: 'Error during speech recognition: InsufficientPermissions'

But this is the Exception i get after running it on my android device.

After looking into the android i have found out about dangerous permissions and that these are the cause of my problem. After many hours of research and testing i have not found a way to open a permission prompt so that i am allowed to use my microphone.

Can anyone explain or help me out with this problem?

Thanks in advance!

1 Answers

Since it's a common requirement, Uno actually offers a few extension to make it easy to request for permissions on Android.

This code is only available on Android

#if __ANDROID__

// This will only check if the permission is granted but will not prompt the user.
bool isGranted = await Windows.Extensions.PermissionsHelper.CheckPermission(ct, Android.Manifest.Permission.RecordAudio);

// This will prompt the user with the native permission dialog if needed. If already granted it will simply return true.
bool isPermissionGranted = await Windows.Extensions.PermissionsHelper.TryGetPermission(ct, Android.Manifest.Permission.RecordAudio);

#endif

Source of that extension is available here

Related