简体   繁体   中英

Hololens 2 / MRTK / Unity / Asking for permissions programmatically

Is it possible to check if app has permissions and if don't ask for permissions programmatically on Hololens 2?

In manifest permissions are already declared by sometimes if you miss the permission popup or click on NO by mistake the app doesn't ask for permission never again.

Unity 2020.3.13f1

MRTK 2.7.3

- Update -

I asked for this feature here:

https://github.com/microsoft/MixedRealityToolkit-Unity/issues/10675

Please support the request!

To check Microphone and Camera permissions on HoloLens 2, we can take advantage of WinRT API MediaCapture . If the app does not have Microphone and Camera permissions, when calling the InitializeAsync method, it will throw a UnauthorizedAccessException .

If we got this exception, there is no way to re-ask for permission programmatically. We should let the user to grant us the required permissions again in Settings with using the ms-settings:appsfeatures-app URI, which can open the advanced settings page for our app.

#if ENABLE_WINMD_SUPPORT
using (MediaCapture mediaCapture = new MediaCapture())
    try
    {
        await mediaCapture.InitializeAsync();       
    }
    catch (UnauthorizedAccessException)
    {
        await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:appsfeatures-app"));
    }
#endif

Another way to check the permissions would be using AppCapability Class . CheckAccess method will return the access status. If the status is DeniedByUser , we will still need to open the advanced settings page for our app using the ms-settings:appsfeatures-app URI and let the user to grant us the required permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM