ProximitySensor

Last Updated On 2021-07-16

Version 1MinSDK 7Tutorial Video

Non-visible component that can measures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a persons ear; i.e. lets you determine how far away an object is from a device. Many devices return the absolute distance, in cm, but some return only near and far values. In this case, the sensor usually reports its maximum range value in the far state and a lesser value in the near state.


Properties

You can set the below properties in the UI part of the builder.

  • Enabled - it's a boolean value which is set to true by default.
  • KeepRunningWhenOnPause - it's a boolean value which is set to false by default.

Block Properties

You can set the below blocks properties in the blocks section of the builder.

Available

Reports whether or not the device has a proximity sensor.


Distance

Returns the distance from the object to the device


Enabled

If true, the sensor will generate events. Otherwise, no events are generated.


KeepRunningWhenOnPause

Returns value of keepRunningWhenOnPause


MaximumRange

Reports the Maximum Range of the device's ProximitySensor



Events

You can set the below event blocks in the blocks section of the builder.

ProximityChanged

Triggered when distance (in cm) of the object to the device changes.