Sensor Class
A sensor object of a document (https://w3c.github.io/sensors/#the-sensor-interface): the base of Accelerometer, Gyroscope, Magnetometer, AmbientLightSensor, OrientationSensor, etc. Sensor.Start connects it to the sensor of its type of the DeviceSensorProvider of the browsing context (DeviceSensorsOptions.Provider) after checking the permissions; the reading event is fired when a new reading is available, at most at the requested frequency, while the document is visible and focused.
public abstract class Sensor : EventTarget- Inheritance
EventTargetSensor
Properties
| Name | Description |
|---|---|
| Activated | Gets whether the sensor is activated: it is started and connected to a sensor of the device. |
| HasReading | Gets whether the sensor has a reading. |
| OnActivate | Gets or sets the event handler of the activate event. |
| OnError | Gets or sets the event handler of the error event. |
| OnReading | Gets or sets the event handler of the reading event. |
| Timestamp | Gets the time of the latest reading, in milliseconds relative to the time origin of the window, or null. |
Activated
Sensor.csGets whether the sensor is activated: it is started and connected to a sensor of the device.
public bool Activated { get; }HasReading
Sensor.csGets whether the sensor has a reading.
public bool HasReading { get; }OnActivate
Sensor.csGets or sets the event handler of the activate event.
OnError
Sensor.csGets or sets the event handler of the error event.
OnReading
Sensor.csGets or sets the event handler of the reading event.
Timestamp
Sensor.csGets the time of the latest reading, in milliseconds relative to the time origin of the window, or null.
public double? Timestamp { get; }Methods
| Name | Description |
|---|---|
| Start() | Starts the sensor (https://w3c.github.io/sensors/#sensor-start): the permissions of the sensor type are requested, then the sensor connects to the sensor of its type of the device, and the activate event is fired. The error event is fired with a NotAllowedError when a permission is denied, and with a NotReadableError when the device has no working sensor of the type. |
| Stop() | Stops the sensor (https://w3c.github.io/sensors/#sensor-stop): it no longer has a reading. |
Start()
Sensor.csStarts the sensor (https://w3c.github.io/sensors/#sensor-start): the permissions of the sensor type are requested, then the sensor connects to the sensor of its type of the device, and the activate event is fired. The error event is fired with a NotAllowedError when a permission is denied, and with a NotReadableError when the device has no working sensor of the type.
public void Start()Stop()
Sensor.csStops the sensor (https://w3c.github.io/sensors/#sensor-stop): it no longer has a reading.
public void Stop()