windows-10-desktopprivacy-policy

Is it possible to query the camera privacy settings for windows 10?


It appears that the Windows 10 April update has changed access permissions for devices such as the camera and microphone, restricting all by default to none.

https://privacy.microsoft.com/en-us/windows-10-camera-and-privacy

enter image description here

I am using a Realsense 435 camera and want to notify the user, when he needs to adjust the privacy settings - something like "Go to Privacy Settings. Select the tab 'Camera' and turn on 'Allow apps to access your camera'".

Is there an API to detect the current state of the camera privacy settings?


Solution

  • Is there an API to detect the current state of the camera privacy settings?

    There's no built-in APIs for you to detect the state of camera privacy settings.

    But we could think about this question from another hand, if the camera settings turn off. When you initialize the camera object, it will throw exception in your code.

    For example: Camera Resolution Line86 If you catch the exception, you could launch the privacy settings page for the camera by using await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-webcam"));

    public async Task InitializeCameraAsync()
    {
            MediaCapture = new MediaCapture();
            MediaCapture.Failed += MediaCapture_Failed;
    
            try
            {
                await MediaCapture.InitializeAsync();
                _previewControl.Source = MediaCapture;
                await MediaCapture.StartPreviewAsync();
                IsPreviewing = true;
            }
            catch (UnauthorizedAccessException)
            {
                // This can happen if access to the camera has been revoked.
                MainPage.Current.NotifyUser("The app was denied access to the camera", NotifyType.ErrorMessage);
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-webcam"));
                await CleanupCameraAsync();
            }
    }