java.lang.Object | ||
↳ | android.os.Binder | |
↳ | 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.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | AXIS_MINUS_X | see remapCoordinateSystem(float[], int, int, float[]) | |||||||||
int | AXIS_MINUS_Y | see remapCoordinateSystem(float[], int, int, float[]) | |||||||||
int | AXIS_MINUS_Z | see remapCoordinateSystem(float[], int, int, float[]) | |||||||||
int | AXIS_X | see remapCoordinateSystem(float[], int, int, float[]) | |||||||||
int | AXIS_Y | see remapCoordinateSystem(float[], int, int, float[]) | |||||||||
int | AXIS_Z | see remapCoordinateSystem(float[], int, int, float[]) | |||||||||
int | DATA_X | Index of the X value in the array returned by onSensorChanged(int, float[]) | |||||||||
int | DATA_Y | Index of the Y value in the array returned by onSensorChanged(int, float[]) | |||||||||
int | DATA_Z | Index of the Z value in the array returned by onSensorChanged(int, float[]) | |||||||||
float | GRAVITY_DEATH_STAR_I | ||||||||||
float | GRAVITY_EARTH | ||||||||||
float | GRAVITY_JUPITER | ||||||||||
float | GRAVITY_MARS | ||||||||||
float | GRAVITY_MERCURY | ||||||||||
float | GRAVITY_MOON | ||||||||||
float | GRAVITY_NEPTUNE | ||||||||||
float | GRAVITY_PLUTO | ||||||||||
float | GRAVITY_SATURN | ||||||||||
float | GRAVITY_SUN | values returned by the accelerometer in various locations in the universe. | |||||||||
float | GRAVITY_THE_ISLAND | ||||||||||
float | GRAVITY_URANUS | ||||||||||
float | GRAVITY_VENUS | ||||||||||
float | LIGHT_CLOUDY | ||||||||||
float | LIGHT_FULLMOON | Various luminance values during the night (lux) | |||||||||
float | LIGHT_NO_MOON | ||||||||||
float | LIGHT_OVERCAST | ||||||||||
float | LIGHT_SHADE | ||||||||||
float | LIGHT_SUNLIGHT | ||||||||||
float | LIGHT_SUNLIGHT_MAX | Various luminance values during the day (lux) | |||||||||
float | LIGHT_SUNRISE | ||||||||||
float | MAGNETIC_FIELD_EARTH_MAX | Maximum magnetic field on Earth's surface | |||||||||
float | MAGNETIC_FIELD_EARTH_MIN | Minimum magnetic field on Earth's surface | |||||||||
int | RAW_DATA_INDEX | Offset to the untransformed values in the array returned by onSensorChanged(int, float[]) | |||||||||
int | RAW_DATA_X | Index of the untransformed X value in the array returned by onSensorChanged(int, float[]) | |||||||||
int | RAW_DATA_Y | Index of the untransformed Y value in the array returned by onSensorChanged(int, float[]) | |||||||||
int | RAW_DATA_Z | Index of the untransformed Z value in the array returned by onSensorChanged(int, float[]) | |||||||||
int | SENSOR_ACCELEROMETER | This constant is deprecated. use Sensor instead. | |||||||||
int | SENSOR_ALL | A constant that includes all sensors | |||||||||
int | SENSOR_DELAY_FASTEST | get sensor data as fast as possible | |||||||||
int | SENSOR_DELAY_GAME | rate suitable for games | |||||||||
int | SENSOR_DELAY_NORMAL | rate (default) suitable for screen orientation changes | |||||||||
int | SENSOR_DELAY_UI | rate suitable for the user interface | |||||||||
int | SENSOR_LIGHT | This constant is deprecated. use Sensor instead. | |||||||||
int | SENSOR_MAGNETIC_FIELD | This constant is deprecated. use Sensor instead. | |||||||||
int | SENSOR_MAX | Largest sensor ID | |||||||||
int | SENSOR_MIN | Smallest sensor ID | |||||||||
int | SENSOR_ORIENTATION | This constant is deprecated. use Sensor instead. | |||||||||
int | SENSOR_ORIENTATION_RAW | This constant is deprecated. use Sensor instead. | |||||||||
int | SENSOR_PROXIMITY | This constant is deprecated. use Sensor instead. | |||||||||
int | SENSOR_STATUS_ACCURACY_HIGH | This sensor is reporting data with maximum accuracy | |||||||||
int | SENSOR_STATUS_ACCURACY_LOW | This sensor is reporting data with low accuracy, calibration with the environment is needed | |||||||||
int | SENSOR_STATUS_ACCURACY_MEDIUM | This sensor is reporting data with an average level of accuracy, calibration with the environment may improve the readings | |||||||||
int | SENSOR_STATUS_UNRELIABLE | The values returned by this sensor cannot be trusted, calibration is needed or the environment doesn't allow readings | |||||||||
int | SENSOR_TEMPERATURE | This constant is deprecated. use Sensor instead. | |||||||||
int | SENSOR_TRICORDER | This constant is deprecated. use Sensor instead. | |||||||||
float | STANDARD_GRAVITY | Standard gravity (g) on Earth. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.os.IBinder
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Retrieve the Binder object associated with this interface.
| |||||||||||
Cast an IBinder object into an IRotationWatcher interface,
generating a proxy if needed.
| |||||||||||
Use this method to get the default sensor for a given type.
| |||||||||||
Computes the geomagnetic inclination angle in radians from the
inclination matrix I returned by getRotationMatrix(float[], float[], float[], float[]).
| |||||||||||
Computes the device's orientation based on the rotation matrix.
| |||||||||||
Computes the inclination matrix I as well as the rotation
matrix R transforming a vector from the
device coordinate system to the world's coordinate system which is
defined as a direct orthonormal basis, where:
| |||||||||||
Use this method to get the list of available sensors of a certain
type.
| |||||||||||
This method is deprecated.
This method is deprecated, use
getSensorList(int) instead
| |||||||||||
Default implementation is a stub that returns false.
| |||||||||||
Registers a SensorEventListener
for the given sensor.
| |||||||||||
This method is deprecated.
This method is deprecated, use
registerListener(SensorEventListener, Sensor, int)
instead.
| |||||||||||
This method is deprecated.
This method is deprecated, use
registerListener(SensorEventListener, Sensor, int)
instead.
| |||||||||||
Registers a SensorEventListener
for the given sensor.
| |||||||||||
Rotates the supplied rotation matrix so it is expressed in a
different coordinate system.
| |||||||||||
This method is deprecated.
This method is deprecated, use
unregisterListener(SensorEventListener)
instead.
| |||||||||||
Unregisters a listener for all sensors.
| |||||||||||
Unregisters a listener for the sensors with which it is registered.
| |||||||||||
This method is deprecated.
This method is deprecated, use
unregisterListener(SensorEventListener, Sensor)
instead.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class android.os.Binder
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface android.os.IBinder
| |||||||||||
From interface android.os.IInterface
|
Index of the X value in the array returned by onSensorChanged(int, float[])
Index of the Y value in the array returned by onSensorChanged(int, float[])
Index of the Z value in the array returned by onSensorChanged(int, float[])
values returned by the accelerometer in various locations in the universe. all values are in SI units (m/s^2)
Various luminance values during the night (lux)
Various luminance values during the day (lux)
Maximum magnetic field on Earth's surface
Minimum magnetic field on Earth's surface
Offset to the untransformed values in the array returned by onSensorChanged(int, float[])
Index of the untransformed X value in the array returned by onSensorChanged(int, float[])
Index of the untransformed Y value in the array returned by onSensorChanged(int, float[])
Index of the untransformed Z value in the array returned by onSensorChanged(int, float[])
This constant is deprecated.use Sensor instead.
A constant describing an accelerometer. See SensorListener for more details.
A constant that includes all sensors
get sensor data as fast as possible
rate suitable for games
rate (default) suitable for screen orientation changes
rate suitable for the user interface
This constant is deprecated.use Sensor instead.
A constant describing an ambient light sensor See SensorListener for more details.
This constant is deprecated.use Sensor instead.
A constant describing a magnetic sensor See SensorListener for more details.
Largest sensor ID
Smallest sensor ID
This constant is deprecated.use Sensor instead.
A constant describing an orientation sensor. See SensorListener for more details.
This constant is deprecated.use Sensor instead.
A constant describing an orientation sensor. See SensorListener for more details.
This constant is deprecated.use Sensor instead.
A constant describing a proximity sensor See SensorListener for more details.
This sensor is reporting data with maximum accuracy
This sensor is reporting data with low accuracy, calibration with the environment is needed
This sensor is reporting data with an average level of accuracy, calibration with the environment may improve the readings
The values returned by this sensor cannot be trusted, calibration is needed or the environment doesn't allow readings
This constant is deprecated.use Sensor instead.
A constant describing a temperature sensor See SensorListener for more details.
This constant is deprecated.use Sensor instead.
A constant describing a Tricorder See SensorListener for more details.
Standard gravity (g) on Earth. This value is equivalent to 1G
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.
Cast an IBinder object into an IRotationWatcher interface, generating a proxy if needed.
Use this method to get the default sensor for a given type. Note that the returned sensor could be a composite sensor, and its data could be averaged or filtered. If you need to access the raw sensors use getSensorList.
type | of sensors requested |
---|
Computes the geomagnetic inclination angle in radians from the inclination matrix I returned by getRotationMatrix(float[], float[], float[], float[]).
I | inclination matrix see getRotationMatrix(float[], float[], float[], float[]). |
---|
Computes the device's orientation based on the rotation matrix.
When it returns, the array values is filled with the result:
R | rotation matrix see getRotationMatrix(float[], float[], float[], float[]). |
---|---|
values | an array of 3 floats to hold the result. |
Computes the inclination matrix I as well as the rotation matrix R transforming a vector from the device coordinate system to the world's coordinate system which is defined as a direct orthonormal basis, where:
By definition:
[0 0 g] = R * gravity (g = magnitude of gravity)
[0 m 0] = I * R * geomagnetic (m = magnitude of geomagnetic field)
R is the identity matrix when the device is aligned with the world's coordinate system, that is, when the device's X axis points toward East, the Y axis points to the North Pole and the device is facing the sky.
I is a rotation matrix transforming the geomagnetic vector into the same coordinate space as gravity (the world's coordinate space). I is a simple rotation around the X axis. The inclination angle in radians can be computed with getInclination(float[]).
Each matrix is returned either as a 3x3 or 4x4 row-major matrix depending on the length of the passed array:
If the array length is 16:
/ M[ 0] M[ 1] M[ 2] M[ 3] \ | M[ 4] M[ 5] M[ 6] M[ 7] | | M[ 8] M[ 9] M[10] M[11] | \ M[12] M[13] M[14] M[15] /This matrix is ready to be used by OpenGL ES's glLoadMatrixf(float[], int).
Note that because OpenGL matrices are column-major matrices you must transpose the matrix before using it. However, since the matrix is a rotation matrix, its transpose is also its inverse, conveniently, it is often the inverse of the rotation that is needed for rendering; it can therefore be used with OpenGL ES directly.
Also note that the returned matrices always have this form:
/ M[ 0] M[ 1] M[ 2] 0 \ | M[ 4] M[ 5] M[ 6] 0 | | M[ 8] M[ 9] M[10] 0 | \ 0 0 0 1 /
If the array length is 9:
/ M[ 0] M[ 1] M[ 2] \ | M[ 3] M[ 4] M[ 5] | \ M[ 6] M[ 7] M[ 8] /
The inverse of each matrix can be computed easily by taking its transpose.
The matrices returned by this function are meaningful only when the device is not free-falling and it is not close to the magnetic north. If the device is accelerating, or placed into a strong magnetic field, the returned matrices may be inaccurate.
R | is an array of 9 floats holding the rotation matrix R when this function returns. R can be null. |
---|---|
I | is an array of 9 floats holding the rotation matrix I when this function returns. I can be null. |
gravity | is an array of 3 floats containing the gravity vector expressed in the device's coordinate. You can simply use the values returned by a SensorEvent of a Sensor of type TYPE_ACCELEROMETER. |
geomagnetic | is an array of 3 floats containing the geomagnetic vector expressed in the device's coordinate. You can simply use the values returned by a SensorEvent of a Sensor of type TYPE_MAGNETIC_FIELD. |
false on failure (for instance, if the device is in free fall). On failure the output matrices are not modified.
Use this method to get the list of available sensors of a certain type. Make multiple calls to get sensors of different types or use Sensor.TYPE_ALL to get all the sensors.
type | of sensors requested |
---|
This method is deprecated.This method is deprecated, use getSensorList(int) instead
RemoteException |
---|
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().
RemoteException |
---|
Registers a SensorEventListener for the given sensor.
listener | A SensorEventListener object. |
---|---|
sensor | The Sensor to register to. |
rate | The rate sensor events are delivered at. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. The value must be one of SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, SENSOR_DELAY_GAME, or SENSOR_DELAY_FASTEST. |
handler | The Handler the sensor events will be delivered to. |
This method is deprecated.This method is deprecated, use registerListener(SensorEventListener, Sensor, int) instead.
Registers a SensorListener for given sensors.
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. The value must be one of SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, SENSOR_DELAY_GAME, or SENSOR_DELAY_FASTEST. |
This method is deprecated.This method is deprecated, use registerListener(SensorEventListener, Sensor, int) instead.
Registers a listener for given sensors.
listener | sensor listener object |
---|---|
sensors | a bit masks of the sensors to register to |
Registers a SensorEventListener for the given sensor.
listener | A SensorEventListener object. |
---|---|
sensor | The Sensor to register to. |
rate | The rate sensor events are delivered at. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. The value must be one of SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, SENSOR_DELAY_GAME, or SENSOR_DELAY_FASTEST. |
Rotates the supplied rotation matrix so it is expressed in a different coordinate system. This is typically used when an application needs to compute the three orientation angles of the device (see getOrientation(float[], float[])) in a different coordinate system.
When the rotation matrix is used for drawing (for instance with OpenGL ES), it usually doesn't need to be transformed by this function, unless the screen is physically rotated, such as when used in landscape mode.
Examples:
remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);
remapCoordinateSystem(inR, AXIS_Y, AXIS_MINUS_X, outR);
Beware of the above example. This call is needed only if the device is physically used in landscape mode to calculate the rotation angles (see getOrientation(float[], float[])). If the rotation matrix is also used for rendering, it may not need to be transformed, for instance if your Activity is running in landscape mode.
Since the resulting coordinate system is orthonormal, only two axes need to be specified.
inR | the rotation matrix to be transformed. Usually it is the matrix returned by getRotationMatrix(float[], float[], float[], float[]). |
---|---|
X | defines on which world axis and direction the X axis of the device is mapped. |
Y | defines on which world axis and direction the Y axis of the device is mapped. |
outR | the transformed rotation matrix. inR and outR can be the same array, but it is not recommended for performance reason. |
This method is deprecated.This method is deprecated, use unregisterListener(SensorEventListener) instead.
Unregisters a listener for all sensors.
listener | a SensorListener object |
---|
Unregisters a listener for all sensors.
listener | a SensorListener object |
---|
Unregisters a listener for the sensors with which it is registered.
listener | a SensorEventListener object |
---|---|
sensor | the sensor to unregister from |
This method is deprecated.This method is deprecated, use unregisterListener(SensorEventListener, Sensor) instead.
Unregisters a listener for the sensors with which it is registered.
listener | a SensorListener object |
---|---|
sensors | a bit masks of the sensors to unregister from |