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