Windows 10 Mobile application. I play audio via the internal speaker, but I'd like to turn off the screen (just like the phone app does) when held to a users head/ear.
I have the problem that the screen stays on, and unwanted touch events are being fired. The built-in Phone call app does this, so I'm assuming that I can access the same API.
The ProximitySensor.CreateDisplayOnOffController will manage this for you:
displayController = sensor.CreateDisplayOnOffController();
So long as your displayController exists the ProximitySensor will manage the screen based on proximity. Dispose the displayController when your app is done with the audio it wants to protect.
See Scenario 3 in the Proximity Sensor sample at https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/ProximitySensor for a full demo, including how to find the Proximity Sensor.