android 4.4 sensormanager,SensorManager

android.hardware.SensorManager

Class Overview

SensorManager lets you access the device's

Always make sure to disable sensors you don't need, especially when your

activity is paused. Failing to do so can drain the battery in just a few

hours. Note that the system will not disable sensors automatically when

the screen turns off.

Note: Don't use this mechanism with a Trigger Sensor, have a look

at

public class SensorActivity extends Activity, implements SensorEventListener {

private final SensorManager mSensorManager;

private final Sensor mAccelerometer;

public SensorActivity() {

mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);

mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

}

protected void onResume() {

super.onResume();

mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);

}

protected void onPause() {

super.onPause();

mSensorManager.unregisterListener(this);

}

public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

public void onSensorChanged(SensorEvent event) {

}

}

Summary

Constants

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

float

Gravity (estimate) on the first Death Star in Empire units (m/s^2)

float

Earth's gravity in SI units (m/s^2)

float

Jupiter's gravity in SI units (m/s^2)

float

Mars' gravity in SI units (m/s^2)

float

Mercury's gravity in SI units (m/s^2)

float

The Moon's gravity in SI units (m/s^2)

float

Neptune's gravity in SI units (m/s^2)

float

Pluto's gravity in SI units (m/s^2)

float

Saturn's gravity in SI units (m/s^2)

float

Sun's gravity in SI units (m/s^2)

float

Gravity on the island

float

Uranus' gravity in SI units (m/s^2)

float

Venus' gravity in SI units (m/s^2)

float

luminance under a cloudy sky in lux

float

luminance at night with full moon in lux

float

luminance at night with no moon in lux

float

luminance under an overcast sky in lux

float

luminance in shade in lux

float

luminance of sunlight in lux

float

Maximum luminance of sunlight in lux

float

luminance at sunrise in lux

float

Maximum magnetic field on Earth's surface

float

Minimum magnetic field on Earth's surface

float

Standard atmosphere, or average sea-level pressure in hPa (millibar)

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

get sensor data as fast as possible

int

rate suitable for games

int

rate (default) suitable for screen orientation changes

int

rate suitable for the user interface

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

int

This sensor is reporting data with maximum accuracy

int

This sensor is reporting data with low accuracy, calibration with the

environment is needed

int

This sensor is reporting data with an average level of accuracy,

calibration with the environment may improve the readings

int

The values returned by this sensor cannot be trusted, calibration is

needed or the environment doesn't allow readings

int

This constant was deprecated

in API level 3.

use

int

This constant was deprecated

in API level 3.

use

float

Standard gravity (g) on Earth.

Public Methods

boolean

Cancels receiving trigger events for a trigger sensor.

boolean

Flushes the batch FIFO of all the sensors registered for this listener.

static

float

Computes the Altitude in meters from the atmospheric pressure and the

pressure at sea level.

static

void

Helper function to compute the angle change between two rotation matrices.

Use this method to get the default sensor for a given type.

static

float

Computes the geomagnetic inclination angle in radians from the

inclination matrix I returned by

static

float[]

Computes the device's orientation based on the rotation matrix.

static

void

Helper function to convert a rotation vector to a normalized quaternion.

static

boolean

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:

X is defined as the vector product Y.Z (It is tangential to

the ground at the device's current location and roughly points East).

static

void

Helper function to convert a rotation vector to a rotation matrix.

Use this method to get the list of available sensors of a certain type.

int

This method was deprecated

in API level 3.

This method is deprecated, use

boolean

SensorListener listener, int sensors, int rate)

This method was deprecated

in API level 3.

This method is deprecated, use

boolean

This method was deprecated

in API level 3.

This method is deprecated, use

boolean

SensorEventListener listener, Sensor sensor, int rateUs, int maxBatchReportLatencyUs)

Enables batch mode for a sensor with the given rate and maxBatchReportLatency.

boolean

Registers a

boolean

SensorEventListener listener, Sensor sensor, int rateUs, int maxBatchReportLatencyUs, Handler handler)

Enables batch mode for a sensor with the given rate and maxBatchReportLatency.

boolean

Registers a

static

boolean

Rotates the supplied rotation matrix so it is expressed in a different

coordinate system.

boolean

Requests receiving trigger events for a trigger sensor.

void

This method was deprecated

in API level 3.

This method is deprecated, use

void

This method was deprecated

in API level 3.

This method is deprecated, use

void

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

void

Unregisters a listener for all sensors.

[Expand]

Inherited Methods

3e54f4822052f69722b015cabe630b87.png

From class

java.lang.Object

Creates and returns a copy of this Object.

boolean

Compares this instance with the specified object and indicates if they

are equal.

void

Invoked when the garbage collector has detected that this instance is no longer reachable.

final

Class>

Returns the unique instance of

int

Returns an integer hash code for this object.

final

void

Causes a thread which is waiting on this object's monitor (by means of

calling one of the wait() methods) to be woken up.

final

void

Causes all threads which are waiting on this object's monitor (by means

of calling one of the wait() methods) to be woken up.

Returns a string containing a concise, human-readable description of this

object.

final

void

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.

final

void

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the

specified timeout expires.

final

void

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the

specified timeout expires.

Constants

public

static

final

int

AXIS_MINUS_X

Constant Value:

129

(0x00000081)

public

static

final

int

AXIS_MINUS_Y

Constant Value:

130

(0x00000082)

public

static

final

int

AXIS_MINUS_Z

Constant Value:

131

(0x00000083)

public

static

final

int

AXIS_X

public

static

final

int

AXIS_Y

public

static

final

int

AXIS_Z

public

static

final

int

DATA_X

This constant was deprecated

in API level 3.

use

Index of the X value in the array returned by

Constant Value:

0

(0x00000000)

public

static

final

int

DATA_Y

This constant was deprecated

in API level 3.

use

Index of the Y value in the array returned by

Constant Value:

1

(0x00000001)

public

static

final

int

DATA_Z

This constant was deprecated

in API level 3.

use

Index of the Z value in the array returned by

Constant Value:

2

(0x00000002)

public

static

final

float

GRAVITY_DEATH_STAR_I

Gravity (estimate) on the first Death Star in Empire units (m/s^2)

Constant Value:

3.5303614E-7

public

static

final

float

GRAVITY_EARTH

Earth's gravity in SI units (m/s^2)

Constant Value:

9.80665

public

static

final

float

GRAVITY_JUPITER

Jupiter's gravity in SI units (m/s^2)

Constant Value:

23.12

public

static

final

float

GRAVITY_MARS

Mars' gravity in SI units (m/s^2)

Constant Value:

3.71

public

static

final

float

GRAVITY_MERCURY

Mercury's gravity in SI units (m/s^2)

Constant Value:

3.7

public

static

final

float

GRAVITY_MOON

The Moon's gravity in SI units (m/s^2)

Constant Value:

1.6

public

static

final

float

GRAVITY_NEPTUNE

Neptune's gravity in SI units (m/s^2)

Constant Value:

11.0

public

static

final

float

GRAVITY_PLUTO

Pluto's gravity in SI units (m/s^2)

Constant Value:

0.6

public

static

final

float

GRAVITY_SATURN

Saturn's gravity in SI units (m/s^2)

Constant Value:

8.96

public

static

final

float

GRAVITY_SUN

Sun's gravity in SI units (m/s^2)

Constant Value:

275.0

public

static

final

float

GRAVITY_THE_ISLAND

Gravity on the island

Constant Value:

4.815162

public

static

final

float

GRAVITY_URANUS

Uranus' gravity in SI units (m/s^2)

Constant Value:

8.69

public

static

final

float

GRAVITY_VENUS

Venus' gravity in SI units (m/s^2)

Constant Value:

8.87

public

static

final

float

LIGHT_CLOUDY

luminance under a cloudy sky in lux

Constant Value:

100.0

public

static

final

float

LIGHT_FULLMOON

luminance at night with full moon in lux

Constant Value:

0.25

public

static

final

float

LIGHT_NO_MOON

luminance at night with no moon in lux

Constant Value:

0.0010

public

static

final

float

LIGHT_OVERCAST

luminance under an overcast sky in lux

Constant Value:

10000.0

public

static

final

float

LIGHT_SHADE

luminance in shade in lux

Constant Value:

20000.0

public

static

final

float

LIGHT_SUNLIGHT

luminance of sunlight in lux

Constant Value:

110000.0

public

static

final

float

LIGHT_SUNLIGHT_MAX

Maximum luminance of sunlight in lux

Constant Value:

120000.0

public

static

final

float

LIGHT_SUNRISE

luminance at sunrise in lux

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

float

PRESSURE_STANDARD_ATMOSPHERE

Standard atmosphere, or average sea-level pressure in hPa (millibar)

Constant Value:

1013.25

public

static

final

int

RAW_DATA_INDEX

This constant was deprecated

in API level 3.

use

Offset to the untransformed values in the array returned by

Constant Value:

3

(0x00000003)

public

static

final

int

RAW_DATA_X

This constant was deprecated

in API level 3.

use

Index of the untransformed X value in the array returned by

Constant Value:

3

(0x00000003)

public

static

final

int

RAW_DATA_Y

This constant was deprecated

in API level 3.

use

Index of the untransformed Y value in the array returned by

Constant Value:

4

(0x00000004)

public

static

final

int

RAW_DATA_Z

This constant was deprecated

in API level 3.

use

Index of the untransformed Z value in the array returned by

Constant Value:

5

(0x00000005)

public

static

final

int

SENSOR_ACCELEROMETER

This constant was deprecated

in API level 3.

use

A constant describing an accelerometer. See

Constant Value:

2

(0x00000002)

public

static

final

int

SENSOR_ALL

This constant was deprecated

in API level 3.

use

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

This constant was deprecated

in API level 3.

use

A constant describing an ambient light sensor See

Constant Value:

16

(0x00000010)

public

static

final

int

SENSOR_MAGNETIC_FIELD

This constant was deprecated

in API level 3.

use

A constant describing a magnetic sensor See

Constant Value:

8

(0x00000008)

public

static

final

int

SENSOR_MAX

This constant was deprecated

in API level 3.

use

Largest sensor ID

Constant Value:

64

(0x00000040)

public

static

final

int

SENSOR_MIN

This constant was deprecated

in API level 3.

use

Smallest sensor ID

Constant Value:

1

(0x00000001)

public

static

final

int

SENSOR_ORIENTATION

This constant was deprecated

in API level 3.

use

A constant describing an orientation sensor. See

Constant Value:

1

(0x00000001)

public

static

final

int

SENSOR_ORIENTATION_RAW

This constant was deprecated

in API level 3.

use

A constant describing an orientation sensor. See

Constant Value:

128

(0x00000080)

public

static

final

int

SENSOR_PROXIMITY

This constant was deprecated

in API level 3.

use

A constant describing a proximity sensor See

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

This constant was deprecated

in API level 3.

use

A constant describing a temperature sensor See

Constant Value:

4

(0x00000004)

public

static

final

int

SENSOR_TRICORDER

This constant was deprecated

in API level 3.

use

A constant describing a Tricorder See

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

boolean

cancelTriggerSensor

Cancels receiving trigger events for a trigger sensor.

Note that a Trigger sensor will be auto disabled if

Parameters

listenerThe listener on which the

sensorThe sensor for which the trigger request should be canceled.

If null, it cancels receiving trigger for all sensors associated

with the listener.

Returns

true if successfully canceled.

Throws

when sensor is a trigger sensor.

public

boolean

flush

Flushes the batch FIFO of all the sensors registered for this listener. If there are events

in the FIFO of the sensor, they are returned as if the batch timeout in the FIFO of the

sensors had expired. Events are returned in the usual way through the SensorEventListener.

This call doesn't affect the batch timeout for this sensor. This call is asynchronous and

returns immediately.

Parameters

listenerA

Returns

true if the flush is initiated successfully on all the sensors

registered for this listener, false if no sensor is previously registered for this

listener or flush on one of the sensors fails.

Throws

public

static

float

getAltitude

(float p0, float p)

Computes the Altitude in meters from the atmospheric pressure and the

pressure at sea level.

Typically the atmospheric pressure is read from a

To calculate altitude differences, you must calculate the difference

between the altitudes at both points. If you don't know the altitude

as sea level, you can use

float altitude_difference =

getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, pressure_at_point2)

- getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, pressure_at_point1);

Parameters

p0pressure at sea level

patmospheric pressure

Returns

Altitude in meters

public

static

void

getAngleChange

(float[] angleChange, float[] R, float[] prevR)

Helper function to compute the angle change between two rotation matrices.

Given a current rotation matrix (R) and a previous rotation matrix

(prevR) computes the rotation around the z,x, and y axes which

transforms prevR to R.

outputs a 3 element vector containing the z,x, and y angle

change at indexes 0, 1, and 2 respectively.

Each input matrix is either as a 3x3 or 4x4 row-major matrix

depending on the length of the passed array:

If the array length is 9, then the array elements represent this matrix/ R[ 0] R[ 1] R[ 2] \

| R[ 3] R[ 4] R[ 5] |

\ R[ 6] R[ 7] R[ 8] /

If the array length is 16, then the array elements represent this matrix/ R[ 0] R[ 1] R[ 2] R[ 3] \

| R[ 4] R[ 5] R[ 6] R[ 7] |

| R[ 8] R[ 9] R[10] R[11] |

\ R[12] R[13] R[14] R[15] /

Parameters

angleChangean an array of floats (z, x, and y) in which the angle change is stored

Rcurrent rotation matrix

prevRprevious rotation matrix

public

Sensor

getDefaultSensor

(int type)

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

Parameters

typeof sensors requested

Returns

the default sensors matching the asked type.

public

static

float

getInclination

(float[] I)

public

static

float[]

getOrientation

(float[] R, float[] values)

Computes the device's orientation based on the rotation matrix.

When it returns, the array values is filled with the result:values[0]: azimuth, rotation around the Z axis.

values[1]: pitch, rotation around the X axis.

values[2]: roll, rotation around the Y axis.

The reference coordinate-system used is different from the world

coordinate-system defined for the rotation matrix:

X is defined as the vector product Y.Z (It is tangential to

the ground at the device's current location and roughly points West).

Y is tangential to the ground at the device's current location and

points towards the magnetic North Pole.

Z points towards the center of the Earth and is perpendicular to the ground.

e01661349ab4f98a0aa744cf13d83cbf.png

All three angles above are in radians and positive in the

counter-clockwise direction.

Parameters

valuesan array of 3 floats to hold the result.

Returns

The array values passed as argument.

public

static

void

getQuaternionFromVector

(float[] Q, float[] rv)

Helper function to convert a rotation vector to a normalized quaternion.

Given a rotation vector (presumably from a ROTATION_VECTOR sensor), returns a normalized

quaternion in the array Q. The quaternion is stored as [w, x, y, z]

Parameters

Qan array of floats in which to store the computed quaternion

rvthe rotation vector to convert

public

static

boolean

getRotationMatrix

(float[] R, float[] I, float[] gravity, float[] geomagnetic)

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:

X is defined as the vector product Y.Z (It is tangential to

the ground at the device's current location and roughly points East).

Y is tangential to the ground at the device's current location and

points towards the magnetic North Pole.

Z points towards the sky and is perpendicular to the ground.

720d8846381aca178294fbb8c2101c5d.png

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

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

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.

Parameters

Ris an array of 9 floats holding the rotation matrix R when

this function returns. R can be null.

Iis an array of 9 floats holding the rotation matrix I when

this function returns. I can be null.

gravityis an array of 3 floats containing the gravity vector expressed in

the device's coordinate. You can simply use the

geomagneticis an array of 3 floats containing the geomagnetic vector

expressed in the device's coordinate. You can simply use the

Returns

true on success, false on failure (for

instance, if the device is in free fall). On failure the output

matrices are not modified.

public

static

void

getRotationMatrixFromVector

(float[] R, float[] rotationVector)

Helper function to convert a rotation vector to a rotation matrix.

Given a rotation vector (presumably from a ROTATION_VECTOR sensor), returns a

9 or 16 element rotation matrix in the array R. R must have length 9 or 16.

If R.length == 9, the following matrix is returned:/ R[ 0] R[ 1] R[ 2] \

| R[ 3] R[ 4] R[ 5] |

\ R[ 6] R[ 7] R[ 8] /

If R.length == 16, the following matrix is returned:

/ R[ 0] R[ 1] R[ 2] 0 \

| R[ 4] R[ 5] R[ 6] 0 |

| R[ 8] R[ 9] R[10] 0 |

\ 0 0 0 1 /

Parameters

Ran array of floats in which to store the rotation matrix

rotationVectorthe rotation vector to convert

getSensorList

(int type)

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

Parameters

typeof sensors requested

Returns

a list of sensors matching the asked type.

public

int

getSensors

()

This method was deprecated

in API level 3.

This method is deprecated, use

Returns

available sensors.

public

boolean

registerListener

(SensorListener listener, int sensors, int rate)

This method was deprecated

in API level 3.

This method is deprecated, use

Registers a SensorListener for given sensors.

Parameters

listenersensor listener object

sensorsa bit masks of the sensors to register to

raterate 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

Returns

true if the sensor is supported and successfully

enabled

public

boolean

registerListener

(SensorListener listener, int sensors)

This method was deprecated

in API level 3.

This method is deprecated, use

Registers a listener for given sensors.

Parameters

listenersensor listener object

sensorsa bit masks of the sensors to register to

Returns

true if the sensor is supported and successfully

enabled

public

boolean

registerListener

(SensorEventListener listener, Sensor sensor, int rateUs, int maxBatchReportLatencyUs)

Enables batch mode for a sensor with the given rate and maxBatchReportLatency. If the

underlying hardware does not support batch mode, this defaults to

Registering to a sensor in batch mode will not prevent the SoC from going to suspend mode. In

this case, the sensor will continue to gather events and store it in a hardware FIFO. If the

FIFO gets full before the AP wakes up again, some events will be lost, as the older events

get overwritten by new events in the hardware FIFO. This can be avoided by holding a wake

lock. If the application holds a wake lock, the SoC will not go to suspend mode, so no events

will be lost, as the events will be reported before the FIFO gets full.

Batching is always best effort. If a different application requests updates in continuous

mode, this application will also get events in continuous mode. Batch mode updates can be

unregistered by calling

Note: Don't use this method with a one shot trigger sensor such as

Parameters

listenerA

sensorThe

rateUsThe desired delay between two consecutive events in microseconds. This is only

a hint to the system. Events may be received faster or slower than the specified

rate. Usually events are received faster. Can be one of

maxBatchReportLatencyUsAn event in the batch can be delayed by at most

maxBatchReportLatency microseconds. More events can be batched if this value is

large. If this is set to zero, batch mode is disabled and events are delivered in

continuous mode as soon as they are available which is equivalent to calling

Returns

true if batch mode is successfully enabled for this sensor,

false otherwise.

public

boolean

registerListener

(SensorEventListener listener, Sensor sensor, int rateUs, Handler handler)

Registers a

Note: Don't use this method with a one shot trigger sensor such as

Parameters

sensorThe

rateUsThe rate SENSOR_DELAY_* constants.

handlerThe

Returns

true if the sensor is supported and successfully enabled.

public

boolean

registerListener

(SensorEventListener listener, Sensor sensor, int rateUs, int maxBatchReportLatencyUs, Handler handler)

Enables batch mode for a sensor with the given rate and maxBatchReportLatency.

Parameters

listenerA

sensorThe

rateUsThe desired delay between two consecutive events in microseconds. This is only

a hint to the system. Events may be received faster or slower than the specified

rate. Usually events are received faster. Can be one of

maxBatchReportLatencyUsAn event in the batch can be delayed by at most

maxBatchReportLatency microseconds. More events can be batched if this value is

large. If this is set to zero, batch mode is disabled and events are delivered in

continuous mode as soon as they are available which is equivalent to calling

handlerThe

Returns

true if batch mode is successfully enabled for this sensor,

false otherwise.

public

boolean

registerListener

(SensorEventListener listener, Sensor sensor, int rateUs)

Registers a

Note: Don't use this method with a one shot trigger sensor such as

Parameters

sensorThe

rateUsThe rate SENSOR_DELAY_* constants.

Returns

true if the sensor is supported and successfully

enabled.

public

static

boolean

remapCoordinateSystem

(float[] inR, int X, int Y, float[] outR)

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

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, in which case you can use

Examples:

Using the camera (Y axis along the camera's axis) for an augmented

reality application where the rotation angles are needed:

remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);

Using the device as a mechanical compass when rotation is

remapCoordinateSystem(inR, AXIS_Y, AXIS_MINUS_X, outR);

Beware of the above example. This call is needed only to account for a

rotation from its natural orientation when calculating the rotation

angles (see

Since the resulting coordinate system is orthonormal, only two axes need

to be specified.

Parameters

inRthe rotation matrix to be transformed. Usually it is the matrix

returned by

Xdefines on which world axis and direction the X axis of the device

is mapped.

Ydefines on which world axis and direction the Y axis of the device

is mapped.

outRthe transformed rotation matrix. inR and outR can be the same

array, but it is not recommended for performance reason.

Returns

true on success. false if the input

parameters are incorrect, for instance if X and Y define the same

axis. Or if inR and outR don't have the same length.

public

boolean

requestTriggerSensor

Requests receiving trigger events for a trigger sensor.

When the sensor detects a trigger event condition, such as significant motion in

the case of the

Parameters

listenerThe listener on which the

sensorThe sensor to be enabled.

Returns

true if the sensor was successfully enabled.

Throws

when sensor is null or not a trigger sensor.

public

void

unregisterListener

This method was deprecated

in API level 3.

This method is deprecated, use

Unregisters a listener for all sensors.

Parameters

listenera SensorListener object

public

void

unregisterListener

(SensorListener listener, int sensors)

This method was deprecated

in API level 3.

This method is deprecated, use

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

Parameters

listenera SensorListener object

sensorsa bit masks of the sensors to unregister from

public

void

unregisterListener

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

Note: Don't use this method with a one shot trigger sensor such as

Parameters

listenera SensorEventListener object

sensorthe sensor to unregister from

public

void

unregisterListener

Except as noted, this content is licensed under Apache 2.0.

For details and restrictions, see the Content License.

Android 4.4 r1 —

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值