to top
Android APIs
public final class

Sensor

extends Object
java.lang.Object
   ↳ android.hardware.Sensor

Class Overview

Class representing a sensor. Use getSensorList(int) to get the list of available Sensors.

Summary

Constants
int TYPE_ACCELEROMETER A constant describing an accelerometer sensor type.
int TYPE_ALL A constant describing all sensor types.
int TYPE_AMBIENT_TEMPERATURE A constant describing an ambient temperature sensor type
int TYPE_GRAVITY A constant describing a gravity sensor type.
int TYPE_GYROSCOPE A constant describing a gyroscope sensor type
int TYPE_LIGHT A constant describing a light sensor type.
int TYPE_LINEAR_ACCELERATION A constant describing a linear acceleration sensor type.
int TYPE_MAGNETIC_FIELD A constant describing a magnetic field sensor type.
int TYPE_ORIENTATION This constant was deprecated in API level 8. use SensorManager.getOrientation() instead.
int TYPE_PRESSURE A constant describing a pressure sensor type
int TYPE_PROXIMITY A constant describing a proximity sensor type.
int TYPE_RELATIVE_HUMIDITY A constant describing a relative humidity sensor type.
int TYPE_ROTATION_VECTOR A constant describing a rotation vector sensor type.
int TYPE_TEMPERATURE This constant was deprecated in API level 14. use Sensor.TYPE_AMBIENT_TEMPERATURE instead.
Public Methods
float getMaximumRange()
int getMinDelay()
String getName()
float getPower()
float getResolution()
int getType()
String getVendor()
int getVersion()
String toString()
Returns a string containing a concise, human-readable description of this object.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int TYPE_ACCELEROMETER

Added in API level 3

A constant describing an accelerometer sensor type. See SensorEvent.values for more details.

Constant Value: 1 (0x00000001)

public static final int TYPE_ALL

Added in API level 3

A constant describing all sensor types.

Constant Value: -1 (0xffffffff)

public static final int TYPE_AMBIENT_TEMPERATURE

Added in API level 14

A constant describing an ambient temperature sensor type

Constant Value: 13 (0x0000000d)

public static final int TYPE_GRAVITY

Added in API level 9

A constant describing a gravity sensor type. See SensorEvent for more details.

Constant Value: 9 (0x00000009)

public static final int TYPE_GYROSCOPE

Added in API level 3

A constant describing a gyroscope sensor type

Constant Value: 4 (0x00000004)

public static final int TYPE_LIGHT

Added in API level 3

A constant describing a light sensor type. See SensorEvent.values for more details.

Constant Value: 5 (0x00000005)

public static final int TYPE_LINEAR_ACCELERATION

Added in API level 9

A constant describing a linear acceleration sensor type. See SensorEvent for more details.

Constant Value: 10 (0x0000000a)

public static final int TYPE_MAGNETIC_FIELD

Added in API level 3

A constant describing a magnetic field sensor type. See SensorEvent.values for more details.

Constant Value: 2 (0x00000002)

public static final int TYPE_ORIENTATION

Added in API level 3

This constant was deprecated in API level 8.
use SensorManager.getOrientation() instead.

A constant describing an orientation sensor type. See SensorEvent.values for more details.

Constant Value: 3 (0x00000003)

public static final int TYPE_PRESSURE

Added in API level 3

A constant describing a pressure sensor type

Constant Value: 6 (0x00000006)

public static final int TYPE_PROXIMITY

Added in API level 3

A constant describing a proximity sensor type. See SensorEvent.values for more details.

Constant Value: 8 (0x00000008)

public static final int TYPE_RELATIVE_HUMIDITY

Added in API level 14

A constant describing a relative humidity sensor type. See SensorEvent for more details.

Constant Value: 12 (0x0000000c)

public static final int TYPE_ROTATION_VECTOR

Added in API level 9

A constant describing a rotation vector sensor type. See SensorEvent for more details.

Constant Value: 11 (0x0000000b)

public static final int TYPE_TEMPERATURE

Added in API level 3

This constant was deprecated in API level 14.
use Sensor.TYPE_AMBIENT_TEMPERATURE instead.

A constant describing a temperature sensor type

Constant Value: 7 (0x00000007)

Public Methods

public float getMaximumRange ()

Added in API level 3

Returns
  • maximum range of the sensor in the sensor's unit.

public int getMinDelay ()

Added in API level 9

Returns
  • the minimum delay allowed between two events in microsecond or zero if this sensor only returns a value when the data it's measuring changes.

public String getName ()

Added in API level 3

Returns
  • name string of the sensor.

public float getPower ()

Added in API level 3

Returns
  • the power in mA used by this sensor while in use

public float getResolution ()

Added in API level 3

Returns
  • resolution of the sensor in the sensor's unit.

public int getType ()

Added in API level 3

Returns
  • generic type of this sensor.

public String getVendor ()

Added in API level 3

Returns
  • vendor string of this sensor.

public int getVersion ()

Added in API level 3

Returns
  • version of the sensor's module.

public String toString ()

Added in API level 3

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.