How to get Microphone privacy setting programmatically

Vijay Gawli 21 Reputation points
2020-03-17T10:35:15.787+00:00

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

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Fay Wang - MSFT 5,196 Reputation points
    2020-03-18T03:12:28.427+00:00

    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
        }
    }
    

0 additional answers

Sort by: Most helpful