Android
android.hardware
public class

android.hardware.SensorManager

java.lang.Object
android.os.Binder IBinder
android.hardware.SensorManager IInterface

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  
int  DATA_X  Index of the X value in the array returned by onSensorChanged(int, float[])   0x00000000 
int  DATA_Y  Index of the Y value in the array returned by onSensorChanged(int, float[])   0x00000001 
int  DATA_Z  Index of the Z value in the array returned by onSensorChanged(int, float[])   0x00000002 
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  RAW_DATA_INDEX  Offset to the raw values in the array returned by onSensorChanged(int, float[])   0x00000003 
int  RAW_DATA_X  Index of the raw X value in the array returned by onSensorChanged(int, float[])   0x00000003 
int  RAW_DATA_Y  Index of the raw X value in the array returned by onSensorChanged(int, float[])   0x00000004 
int  RAW_DATA_Z  Index of the raw X value in the array returned by onSensorChanged(int, float[])   0x00000005 
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_ORIENTATION_RAW  A constant describing an orientation sensor.  128  0x00000080 
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_STATUS_ACCURACY_HIGH  This sensor is reporting data with maximum accuracy   0x00000003 
int  SENSOR_STATUS_ACCURACY_LOW  This sensor is reporting data with low accuracy, calibration with the environment is needed   0x00000001 
int  SENSOR_STATUS_ACCURACY_MEDIUM  This sensor is reporting data with an average level of accuracy, calibration with the environment may improve the readings   0x00000002 
int  SENSOR_STATUS_UNRELIABLE  The values returned by this sensor cannot be trusted, calibration is needed or the environment doesn't allow readings   0x00000000 
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 
Constants inherited from interface android.os.IBinder

Public Methods

          IBinder  asBinder()
Retrieve the Binder object associated with this interface.
      static    IRotationWatcher  asInterface(IBinder obj)
Cast an IBinder object into an IRotationWatcher interface, generating a proxy if needed.
          int  getSensors()
          void  onRotationChanged(int rotation)
          boolean  onTransact(int code, Parcel data, Parcel reply, int flags)
Default implementation is a stub that returns false.
          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 android.os.Binder
Methods inherited from class java.lang.Object
Methods inherited from interface android.os.IBinder
Methods inherited from interface android.os.IInterface

Details

Constants

public static final int DATA_X

Index of the X value in the array returned by onSensorChanged(int, float[])
Constant Value: 0 (0x00000000)

public static final int DATA_Y

Index of the Y value in the array returned by onSensorChanged(int, float[])
Constant Value: 1 (0x00000001)

public static final int DATA_Z

Index of the Z value in the array returned by onSensorChanged(int, float[])
Constant Value: 2 (0x00000002)

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 RAW_DATA_INDEX

Offset to the raw values in the array returned by onSensorChanged(int, float[])
Constant Value: 3 (0x00000003)

public static final int RAW_DATA_X

Index of the raw X value in the array returned by onSensorChanged(int, float[])
Constant Value: 3 (0x00000003)

public static final int RAW_DATA_Y

Index of the raw X value in the array returned by onSensorChanged(int, float[])
Constant Value: 4 (0x00000004)

public static final int RAW_DATA_Z

Index of the raw X value in the array returned by onSensorChanged(int, float[])
Constant Value: 5 (0x00000005)

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_ORIENTATION_RAW

A constant describing an orientation sensor. Sensor values are yaw, pitch and roll Yaw is the compass heading in degrees, 0 <= range < 360 0 = North, 90 = East, 180 = South, 270 = West This is similar to SENSOR_ORIENTATION except the data is not smoothed or filtered in any way.
Constant Value: 128 (0x00000080)

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_STATUS_ACCURACY_HIGH

This sensor is reporting data with maximum accuracy
Constant Value: 3 (0x00000003)

public static final int SENSOR_STATUS_ACCURACY_LOW

This sensor is reporting data with low accuracy, calibration with the environment is needed
Constant Value: 1 (0x00000001)

public static final int SENSOR_STATUS_ACCURACY_MEDIUM

This sensor is reporting data with an average level of accuracy, calibration with the environment may improve the readings
Constant Value: 2 (0x00000002)

public static final int SENSOR_STATUS_UNRELIABLE

The values returned by this sensor cannot be trusted, calibration is needed or the environment doesn't allow readings
Constant Value: 0 (0x00000000)

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 IBinder asBinder()

Retrieve the Binder object associated with this interface. You must use this instead of a plain cast, so that proxy objects can return the correct result.

public static IRotationWatcher asInterface(IBinder obj)

Cast an IBinder object into an IRotationWatcher interface, generating a proxy if needed.

public int getSensors()

Returns

  • available sensors

public void onRotationChanged(int rotation)

public boolean onTransact(int code, Parcel data, Parcel reply, int flags)

Default implementation is a stub that returns false. You will want to override this to do the appropriate unmarshalling of transactions.

If you want to call this, call transact().

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 110632-110632 - 22 Sep 2008 13:34