Android
android.hardware
public class

android.hardware.SensorManager

java.lang.Object
android.hardware.SensorManager

Class that lets you access the device's sensors. Get an instance of this class by calling Context.getSystemService() with an argument of SENSOR_SERVICE.

Summary

Constants

      Value  
float  GRAVITY_DEATH_STAR_I    3.5303614E-7 
float  GRAVITY_EARTH    9.80665 
float  GRAVITY_JUPITER    23.12 
float  GRAVITY_MARS    3.71 
float  GRAVITY_MERCURY    3.7 
float  GRAVITY_MOON    1.6 
float  GRAVITY_NEPTUN    11.0 
float  GRAVITY_PLUTO    0.6 
float  GRAVITY_SATURN    8.96 
float  GRAVITY_SUN  values returned by the accelerometer in various locations in the universe.  275.0 
float  GRAVITY_THE_ISLAND    4.815162 
float  GRAVITY_URANUS    8.69 
float  GRAVITY_VENUS    8.87 
float  LIGHT_CLOUDY    100.0 
float  LIGHT_FULLMOON  Various luminance values during the night (lux)   0.25 
float  LIGHT_NO_MOON    0.0010 
float  LIGHT_OVERCAST    10000.0 
float  LIGHT_SHADE    20000.0 
float  LIGHT_SUNLIGHT    110000.0 
float  LIGHT_SUNLIGHT_MAX  Various luminance values during the day (lux)   120000.0 
float  LIGHT_SUNRISE    400.0 
float  MAGNETIC_FIELD_EARTH_MAX  Maximum magnetic field on Earth's surface   60.0 
float  MAGNETIC_FIELD_EARTH_MIN  Minimum magnetic field on Earth's surface   30.0 
int  SENSOR_ACCELEROMETER  A constant describing an accelerometer.  0x00000002 
int  SENSOR_ALL  A constant that includes all sensors   127  0x0000007f 
int  SENSOR_DELAY_FASTEST  get sensor data as fast as possible   0x00000000 
int  SENSOR_DELAY_GAME  rate suitable for games   0x00000001 
int  SENSOR_DELAY_NORMAL  rate (default) suitable for screen orientation changes   0x00000003 
int  SENSOR_DELAY_UI  rate suitable for the user interface   0x00000002 
int  SENSOR_LIGHT  A constant describing an ambient light sensor Only the first value is defined for this sensor and it contains the ambient light measure in lux.  16  0x00000010 
int  SENSOR_MAGNETIC_FIELD  A constant describing a magnetic sensor Sensor values are the magnetic vector in the X, Y and Z axis, where the X axis has positive direction toward the right side of the device, the Y axis has positive direction toward the top of the device and the Z axis has positive direction toward the front of the device.  0x00000008 
int  SENSOR_MAX  Largest sensor ID   64  0x00000040 
int  SENSOR_MIN  Smallest sensor ID   0x00000001 
int  SENSOR_ORIENTATION  A constant describing an orientation sensor.  0x00000001 
int  SENSOR_PROXIMITY  A constant describing a proximity sensor Only the first value is defined for this sensor and it contains the distance between the sensor and the object in meters (m)   32  0x00000020 
int  SENSOR_TEMPERATURE  A constant describing a temperature sensor Only the first value is defined for this sensor and it contains the ambient temperature in degree C.  0x00000004 
int  SENSOR_TRICORDER  A constant describing a Tricorder When this sensor is available and enabled, the device can be used as a fully functional Tricorder.  64  0x00000040 
float  STANDARD_GRAVITY  Standard gravity (g) on Earth.  9.80665 

Public Methods

          int  getSensors()
      static    void  mapSensorDataToWindow(int sensor, float[] values, int orientation)
Helper function to convert the specified sensor's data to the windows's coordinate space from the device's coordinate space.
          boolean  registerListener(SensorListener listener, int sensors)
Registers a listener for given sensors.
          boolean  registerListener(SensorListener listener, int sensors, int rate)
Registers a listener for given sensors.
          void  unregisterListener(SensorListener listener, int sensors)
Unregisters a listener for the sensors with which it is registered.
          void  unregisterListener(SensorListener listener)
Unregisters a listener for all sensors.
Methods inherited from class java.lang.Object

Details

Constants

public static final float GRAVITY_DEATH_STAR_I

Constant Value: 3.5303614E-7

public static final float GRAVITY_EARTH

Constant Value: 9.80665

public static final float GRAVITY_JUPITER

Constant Value: 23.12

public static final float GRAVITY_MARS

Constant Value: 3.71

public static final float GRAVITY_MERCURY

Constant Value: 3.7

public static final float GRAVITY_MOON

Constant Value: 1.6

public static final float GRAVITY_NEPTUN

Constant Value: 11.0

public static final float GRAVITY_PLUTO

Constant Value: 0.6

public static final float GRAVITY_SATURN

Constant Value: 8.96

public static final float GRAVITY_SUN

values returned by the accelerometer in various locations in the universe. all values are in SI units (m/s^2)
Constant Value: 275.0

public static final float GRAVITY_THE_ISLAND

Constant Value: 4.815162

public static final float GRAVITY_URANUS

Constant Value: 8.69

public static final float GRAVITY_VENUS

Constant Value: 8.87

public static final float LIGHT_CLOUDY

Constant Value: 100.0

public static final float LIGHT_FULLMOON

Various luminance values during the night (lux)
Constant Value: 0.25

public static final float LIGHT_NO_MOON

Constant Value: 0.0010

public static final float LIGHT_OVERCAST

Constant Value: 10000.0

public static final float LIGHT_SHADE

Constant Value: 20000.0

public static final float LIGHT_SUNLIGHT

Constant Value: 110000.0

public static final float LIGHT_SUNLIGHT_MAX

Various luminance values during the day (lux)
Constant Value: 120000.0

public static final float LIGHT_SUNRISE

Constant Value: 400.0

public static final float MAGNETIC_FIELD_EARTH_MAX

Maximum magnetic field on Earth's surface
Constant Value: 60.0

public static final float MAGNETIC_FIELD_EARTH_MIN

Minimum magnetic field on Earth's surface
Constant Value: 30.0

public static final int SENSOR_ACCELEROMETER

A constant describing an accelerometer. Sensor values are acceleration in the X, Y and Z axis, where the X axis has positive direction toward the right side of the device, the Y axis has positive direction toward the top of the device and the Z axis has positive direction toward the front of the device. The direction of the force of gravity is indicated by acceleration values in the X, Y and Z axes. The typical case where the device is flat relative to the surface of the Earth appears as -STANDARD_GRAVITY in the Z axis and X and Z values close to zero. Acceleration values are given in SI units (m/s^2)
Constant Value: 2 (0x00000002)

public static final int SENSOR_ALL

A constant that includes all sensors
Constant Value: 127 (0x0000007f)

public static final int SENSOR_DELAY_FASTEST

get sensor data as fast as possible
Constant Value: 0 (0x00000000)

public static final int SENSOR_DELAY_GAME

rate suitable for games
Constant Value: 1 (0x00000001)

public static final int SENSOR_DELAY_NORMAL

rate (default) suitable for screen orientation changes
Constant Value: 3 (0x00000003)

public static final int SENSOR_DELAY_UI

rate suitable for the user interface
Constant Value: 2 (0x00000002)

public static final int SENSOR_LIGHT

A constant describing an ambient light sensor Only the first value is defined for this sensor and it contains the ambient light measure in lux.
Constant Value: 16 (0x00000010)

public static final int SENSOR_MAGNETIC_FIELD

A constant describing a magnetic sensor Sensor values are the magnetic vector in the X, Y and Z axis, where the X axis has positive direction toward the right side of the device, the Y axis has positive direction toward the top of the device and the Z axis has positive direction toward the front of the device. Magnetic values are given in micro-Tesla (uT)
Constant Value: 8 (0x00000008)

public static final int SENSOR_MAX

Largest sensor ID
Constant Value: 64 (0x00000040)

public static final int SENSOR_MIN

Smallest sensor ID
Constant Value: 1 (0x00000001)

public static final int SENSOR_ORIENTATION

A constant describing an orientation sensor. Sensor values are yaw, pitch and roll Yaw is the compass heading in degrees, range [0, 360[ 0 = North, 90 = East, 180 = South, 270 = West Pitch indicates the tilt of the top of the device, with range -90 to 90. Positive values indicate that the bottom of the device is tilted up and negative values indicate the top of the device is tilted up. Roll indicates the side to side tilt of the device, with range -90 to 90. Positive values indicate that the left side of the device is tilted up and negative values indicate the right side of the device is tilted up.
Constant Value: 1 (0x00000001)

public static final int SENSOR_PROXIMITY

A constant describing a proximity sensor Only the first value is defined for this sensor and it contains the distance between the sensor and the object in meters (m)
Constant Value: 32 (0x00000020)

public static final int SENSOR_TEMPERATURE

A constant describing a temperature sensor Only the first value is defined for this sensor and it contains the ambient temperature in degree C.
Constant Value: 4 (0x00000004)

public static final int SENSOR_TRICORDER

A constant describing a Tricorder When this sensor is available and enabled, the device can be used as a fully functional Tricorder. All values are returned in SI units.
Constant Value: 64 (0x00000040)

public static final float STANDARD_GRAVITY

Standard gravity (g) on Earth. This value is equivalent to 1G
Constant Value: 9.80665

Public Methods

public int getSensors()

Returns

  • available sensors

public static void mapSensorDataToWindow(int sensor, float[] values, int orientation)

Helper function to convert the specified sensor's data to the windows's coordinate space from the device's coordinate space. This is relevant only when the window is not oriented to the natural screen's orientation. This helper is useful when the sensor data is to be used to display graphical elements; for example in the case of the acceleration sensor an application may want to consider that the Y axis always points "up" with respect to the window's UI. This mapping is meaningful only for acceleration, orientation and magnetic sensors and in a certain way to the application itself.

Parameters

orientation the orientation of the window the sensors data is to be used with only acceptable values are 0 (natural orientation, usually portrait) and 90 (rotated window, usually landscape).

public boolean registerListener(SensorListener listener, int sensors)

Registers a listener for given sensors.

Parameters

listener sensor listener object
sensors a bit masks of the sensors to register to

Returns

  • true if the sensor is supported and successfully enabled

public boolean registerListener(SensorListener listener, int sensors, int rate)

Registers a listener for given sensors.

Parameters

listener sensor listener object
sensors a bit masks of the sensors to register to
rate rate of events. This is only a hint to the system. events may be received faster or slower than the specified rate. Usually events are received faster.

Returns

  • true if the sensor is supported and successfully enabled

public void unregisterListener(SensorListener listener, int sensors)

Unregisters a listener for the sensors with which it is registered.

Parameters

listener a SensorListener object
sensors a bit masks of the sensors to unregister from

public void unregisterListener(SensorListener listener)

Unregisters a listener for all sensors.

Parameters

listener a SensorListener object
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48