ProximitySensor ProximitySensor ProximitySensor ProximitySensor Class

Definition

Provides an interface for a proximity sensor to determine whether or not an object is detected.

For an example implementation, see the proximity sensor sample.

public : sealed class ProximitySensor : IProximitySensorpublic sealed class ProximitySensor : IProximitySensorPublic NotInheritable Class ProximitySensor Implements IProximitySensor// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Properties

DeviceId DeviceId DeviceId DeviceId

Gets the device identifier.

public : PlatForm::String DeviceId { get; }public string DeviceId { get; }Public ReadOnly Property DeviceId As string// You can use this property in JavaScript.
Value
PlatForm::String string string string

The device identifier.

MaxDistanceInMillimeters MaxDistanceInMillimeters MaxDistanceInMillimeters MaxDistanceInMillimeters

The largest distance where the proximity sensor can detect an object.

public : IReference<uint> MaxDistanceInMillimeters { get; }public Nullable<uint> MaxDistanceInMillimeters { get; }Public ReadOnly Property MaxDistanceInMillimeters As Nullable<uint>// You can use this property in JavaScript.
Value
IReference<unsigned int> Nullable<uint> Nullable<uint> Nullable<uint>

The maximum distance in millimeters where the proximity sensor supports detecting an object.

MinDistanceInMillimeters MinDistanceInMillimeters MinDistanceInMillimeters MinDistanceInMillimeters

The shortest distance where the proximity sensor can detect an object.

public : IReference<uint> MinDistanceInMillimeters { get; }public Nullable<uint> MinDistanceInMillimeters { get; }Public ReadOnly Property MinDistanceInMillimeters As Nullable<uint>// You can use this property in JavaScript.
Value
IReference<unsigned int> Nullable<uint> Nullable<uint> Nullable<uint>

The minimum distance in millimeters where the proximity sensor supports detecting an object.

Methods

CreateDisplayOnOffController() CreateDisplayOnOffController() CreateDisplayOnOffController() CreateDisplayOnOffController()

Creates a controller responsible for turning the display on or off based on the ProximitySensorReading.

public : ProximitySensorDisplayOnOffController CreateDisplayOnOffController()public ProximitySensorDisplayOnOffController CreateDisplayOnOffController()Public Function CreateDisplayOnOffController() As ProximitySensorDisplayOnOffController// You can use this method in JavaScript.
Returns

FromId(String) FromId(String) FromId(String) FromId(String)

Obtains the proximity sensor from its identifier.

public : static ProximitySensor FromId(PlatForm::String sensorId)public static ProximitySensor FromId(String sensorId)Public Static Function FromId(sensorId As String) As ProximitySensor// You can use this method in JavaScript.
Parameters
sensorId
PlatForm::String String String String

The sensor identifier.

Returns

GetCurrentReading() GetCurrentReading() GetCurrentReading() GetCurrentReading()

Gets the current reading for the proximity sensor.

public : ProximitySensorReading GetCurrentReading()public ProximitySensorReading GetCurrentReading()Public Function GetCurrentReading() As ProximitySensorReading// You can use this method in JavaScript.
Returns

Indicates whether or not the proximity sensor detects an object, and if so, the distance to that object.

GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector()

Gets the device selector.

public : static PlatForm::String GetDeviceSelector()public static string GetDeviceSelector()Public Static Function GetDeviceSelector() As string// You can use this method in JavaScript.
Returns
PlatForm::String string string string

Returns the device selector. If no device selector is available, this method returns null.

GetReadingsFromTriggerDetails(SensorDataThresholdTriggerDetails) GetReadingsFromTriggerDetails(SensorDataThresholdTriggerDetails) GetReadingsFromTriggerDetails(SensorDataThresholdTriggerDetails) GetReadingsFromTriggerDetails(SensorDataThresholdTriggerDetails)

Gets readings from the trigger details in background task.

public : static IVectorView<ProximitySensorReading> GetReadingsFromTriggerDetails(SensorDataThresholdTriggerDetails triggerDetails)public static IReadOnlyList<ProximitySensorReading> GetReadingsFromTriggerDetails(SensorDataThresholdTriggerDetails triggerDetails)Public Static Function GetReadingsFromTriggerDetails(triggerDetails As SensorDataThresholdTriggerDetails) As IReadOnlyList( Of ProximitySensorReading )// You can use this method in JavaScript.
Parameters
Returns
IVectorView<ProximitySensorReading> IReadOnlyList<ProximitySensorReading> IReadOnlyList<ProximitySensorReading> IReadOnlyList<ProximitySensorReading>

The collection of proximity data retrieved from the trigger details.

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

Remarks

SensorDataThresholdTriggerDetails objects are designed to be independent of the sensor that activated the background trigger. This enables you to support all of the sensors your are interested in with a single background task. In order to support this methodology, you need to define this method in all of your sensors that extract data from the background trigger.

Events

ReadingChanged ReadingChanged ReadingChanged ReadingChanged

Occurs each time the proximity sensor reports a new value.

public : event TypedEventHandler ReadingChanged<ProximitySensor,  ProximitySensorReadingChangedEventArgs>public event TypedEventHandler ReadingChanged<ProximitySensor,  ProximitySensorReadingChangedEventArgs>Public Event ReadingChanged<ProximitySensor,  ProximitySensorReadingChangedEventArgs>// You can use this event in JavaScript.

Remarks

An application may register this event handler to obtain sensor readings.