UWP Cordova-如何检查相机权限的状态并相应地将用户导航到相机设置页面?

UWP Cordova- How to check status of camera permission and accordingly navigate user to camera settings page?

正在开发支持 windows 10 设备的 UWP cordova 应用程序。目前我无法检查相机权限的状态。我也看不到相机权限弹出窗口。如果我禁用相机权限,应用程序不会显示任何系统默认弹出窗口?

我使用了 cordova-plugin-diagnostic,但它只是检查设备是否有摄像头。它无法检查相机权限。如果有人可以帮助检查相机权限并将用户导航到 cordova UWP 应用程序中的相机设置页面,那就太好了。

作为文档,

An UnauthorizedAccessException will be thrown when you attempt to initialize the camera if the user has disabled camera access in the device's privacy settings. You will also see this exception during development if you have neglected to add the proper capabilities to your app manifest.

您可以在 camera.onError to get the info whether the camera permission has been enabled. Then you can guide the customer to the setting page to enable this permission. See the How to launch the Settings app 主题中查看此异常信息以获取详细信息。

---更新---

要使用 javascript 实现将您的应用路由到相机设置页面,您可以尝试以下示例代码。

 // The URI to launch
 var uriToLaunch = "ms-settings:privacy-webcam";
 var uri = new Windows.Foundation.Uri(uriToLaunch);
 Windows.System.Launcher.launchUriAsync(uri).then(
     function (success) {
         if (success) {
             // URI launched
         } else {
             // URI launch failed
         }
     });