question

VijayGawli-1160 avatar image
0 Votes"
VijayGawli-1160 asked ·

How to get Microphone privacy setting programmatically

Is there way to get the Microphone privacy setting pro-grammatically - https://hub.mangoapps.com/sf/MjE3NjQ1XzE5NjI1OTM ?

uwp
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered ·

Hello,

​Welcome to our Microsoft Q&A platform!

If you want to get the Microphone setting for the entire computer, there is no api can achieve it in UWP.

But if you want to get microphone permission status for your app, it is feasible.

First you need to accept the Microsoft Privacy Policy granting permission for your app to use it. Set the Microphone device capability in the manifest file and when run the app, it will show a system dialog requesting permission about Microphone, clicks Yes and then your app has access to the microphone. In that case, you can try the following code to check if Microphone is disable. If microphone permission is off, then the method will throw System.UnauthorizedAccessException, you can set IsMicAvailable as false when catching the exception.

 bool IsMicAvailable = true;
 try
     {
         MediaCapture mediaCapture = new MediaCapture();
         var settings = new MediaCaptureInitializationSettings();
         settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
         await mediaCapture.InitializeAsync(settings);
     }
     catch (Exception exception)
     {
         IsMicAvailable = false;
     }

     if (IsMicAvailable)
     {
         //do something
     }
     else
     {
         //do something
     }
 }



· 4 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello,

Thank you for the solution. Yes, its solve my 80% issue.

Is there any way to detect the setting "Allow desktop apps to access your microphone" - https://hub.mangoapps.com/sf/MjE3ODIyXzE5NjI4OTI ?

0 Votes 0 · ·

Nope, you can't detect the setting "Allow desktop apps to access your microphone" in uwp, but can get microphone permission status for your app.

0 Votes 0 · ·

Thank you for your valuable response.

Can you please share the solution if you have to get microphone permission status for your app?

Thank you once again.

0 Votes 0 · ·
Show more comments