cordovauwpcameracordova-pluginscordova-windows

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


Developing UWP cordova applications which supports windows 10 device. Currently I am not able to check the status of camera permission. I am not able to see camera permission popup also. If I disabled the camera permission, app is not showing any system default popup?

I have used cordova-plugin-diagnostic, but it's just checking whether device has camera or not. It's not capable to check camera permission. It would be very greatful if someone could help out to check camera permission and navigate user to camera settings page in cordova UWP apps.


Solution

  • As the document,

    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.

    You can check this exception info in the 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 topic to get the details.

    ---Update---

    To achieve routing of your app to camera setting page using javascript, you can try the following example code.

     // 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
             }
         });