public final class Sensor extends Object
SensorManager.getSensorList(int)
to get
the list of available Sensors.SensorManager
,
SensorEventListener
,
SensorEvent
Modifier and Type | Field and Description |
---|---|
static int |
REPORTING_MODE_CONTINUOUS
Events are reported at a constant rate which is set by the rate parameter of
SensorManager.registerListener(SensorEventListener, Sensor, int) . |
static int |
REPORTING_MODE_ON_CHANGE
Events are reported only when the value changes.
|
static int |
REPORTING_MODE_ONE_SHOT
Events are reported in one-shot mode.
|
static int |
REPORTING_MODE_SPECIAL_TRIGGER
Events are reported as described in the description of the sensor.
|
static String |
SENSOR_STRING_TYPE_TILT_DETECTOR
A constant string describing a wake up tilt detector sensor type.
|
static String |
STRING_TYPE_ACCELEROMETER
A constant string describing an accelerometer sensor type.
|
static String |
STRING_TYPE_AMBIENT_TEMPERATURE
A constant string describing an ambient temperature sensor type.
|
static String |
STRING_TYPE_DEVICE_ORIENTATION
A constant string describing a device orientation sensor type.
|
static String |
STRING_TYPE_DYNAMIC_SENSOR_META
A constant string describing a dynamic sensor meta event sensor.
|
static String |
STRING_TYPE_GAME_ROTATION_VECTOR
A constant string describing an uncalibrated rotation vector sensor type.
|
static String |
STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR
A constant string describing a geo-magnetic rotation vector.
|
static String |
STRING_TYPE_GLANCE_GESTURE
A constant string describing a wake gesture sensor.
|
static String |
STRING_TYPE_GRAVITY
A constant string describing a gravity sensor type.
|
static String |
STRING_TYPE_GYROSCOPE
A constant string describing a gyroscope sensor type.
|
static String |
STRING_TYPE_GYROSCOPE_UNCALIBRATED
A constant string describing an uncalibrated gyroscope sensor type.
|
static String |
STRING_TYPE_HEART_BEAT
A constant string describing a heart beat sensor.
|
static String |
STRING_TYPE_HEART_RATE
A constant string describing a heart rate monitor.
|
static String |
STRING_TYPE_LIGHT
A constant string describing a light sensor type.
|
static String |
STRING_TYPE_LINEAR_ACCELERATION
A constant string describing a linear acceleration sensor type.
|
static String |
STRING_TYPE_MAGNETIC_FIELD
A constant string describing a magnetic field sensor type.
|
static String |
STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED
A constant string describing an uncalibrated magnetic field sensor type.
|
static String |
STRING_TYPE_MOTION_DETECT
A constant string describing a motion detection sensor.
|
static String |
STRING_TYPE_ORIENTATION
Deprecated.
use
SensorManager.getOrientation() instead. |
static String |
STRING_TYPE_PICK_UP_GESTURE
A constant string describing a pick up sensor.
|
static String |
STRING_TYPE_POSE_6DOF
A constant string describing a pose sensor with 6 degrees of freedom.
|
static String |
STRING_TYPE_PRESSURE
A constant string describing a pressure sensor type.
|
static String |
STRING_TYPE_PROXIMITY
A constant string describing a proximity sensor type.
|
static String |
STRING_TYPE_RELATIVE_HUMIDITY
A constant string describing a relative humidity sensor type
|
static String |
STRING_TYPE_ROTATION_VECTOR
A constant string describing a rotation vector sensor type.
|
static String |
STRING_TYPE_SIGNIFICANT_MOTION
A constant string describing a significant motion trigger sensor.
|
static String |
STRING_TYPE_STATIONARY_DETECT
A constant string describing a stationary detection sensor.
|
static String |
STRING_TYPE_STEP_COUNTER
A constant string describing a step counter sensor.
|
static String |
STRING_TYPE_STEP_DETECTOR
A constant string describing a step detector sensor.
|
static String |
STRING_TYPE_TEMPERATURE
Deprecated.
use
Sensor.STRING_TYPE_AMBIENT_TEMPERATURE instead. |
static String |
STRING_TYPE_WAKE_GESTURE
A constant string describing a wake gesture sensor.
|
static String |
STRING_TYPE_WRIST_TILT_GESTURE
A constant string describing a wrist tilt gesture sensor.
|
static int |
TYPE_ACCELEROMETER
A constant describing an accelerometer sensor type.
|
static int |
TYPE_ALL
A constant describing all sensor types.
|
static int |
TYPE_AMBIENT_TEMPERATURE
A constant describing an ambient temperature sensor type.
|
static int |
TYPE_DEVICE_ORIENTATION
The current orientation of the device.
|
static int |
TYPE_DEVICE_PRIVATE_BASE
The lowest sensor type vendor defined sensors can use.
|
static int |
TYPE_DYNAMIC_SENSOR_META
A constant describing a dynamic sensor meta event sensor.
|
static int |
TYPE_GAME_ROTATION_VECTOR
A constant describing an uncalibrated rotation vector sensor type.
|
static int |
TYPE_GEOMAGNETIC_ROTATION_VECTOR
A constant describing a geo-magnetic rotation vector.
|
static int |
TYPE_GLANCE_GESTURE
A constant describing a wake gesture sensor.
|
static int |
TYPE_GRAVITY
A constant describing a gravity sensor type.
|
static int |
TYPE_GYROSCOPE
A constant describing a gyroscope sensor type.
|
static int |
TYPE_GYROSCOPE_UNCALIBRATED
A constant describing an uncalibrated gyroscope sensor type.
|
static int |
TYPE_HEART_BEAT
A constant describing a motion detect sensor.
|
static int |
TYPE_HEART_RATE
A constant describing a heart rate monitor.
|
static int |
TYPE_LIGHT
A constant describing a light sensor type.
|
static int |
TYPE_LINEAR_ACCELERATION
A constant describing a linear acceleration sensor type.
|
static int |
TYPE_MAGNETIC_FIELD
A constant describing a magnetic field sensor type.
|
static int |
TYPE_MAGNETIC_FIELD_UNCALIBRATED
A constant describing an uncalibrated magnetic field sensor type.
|
static int |
TYPE_MOTION_DETECT
A constant describing a motion detect sensor.
|
static int |
TYPE_ORIENTATION
Deprecated.
use
SensorManager.getOrientation() instead. |
static int |
TYPE_PICK_UP_GESTURE
A constant describing a pick up sensor.
|
static int |
TYPE_POSE_6DOF
A constant describing a pose sensor with 6 degrees of freedom.
|
static int |
TYPE_PRESSURE
A constant describing a pressure sensor type.
|
static int |
TYPE_PROXIMITY
A constant describing a proximity sensor type.
|
static int |
TYPE_RELATIVE_HUMIDITY
A constant describing a relative humidity sensor type.
|
static int |
TYPE_ROTATION_VECTOR
A constant describing a rotation vector sensor type.
|
static int |
TYPE_SIGNIFICANT_MOTION
A constant describing a significant motion trigger sensor.
|
static int |
TYPE_STATIONARY_DETECT
A constant describing a stationary detect sensor.
|
static int |
TYPE_STEP_COUNTER
A constant describing a step counter sensor.
|
static int |
TYPE_STEP_DETECTOR
A constant describing a step detector sensor.
|
static int |
TYPE_TEMPERATURE
Deprecated.
use
Sensor.TYPE_AMBIENT_TEMPERATURE instead. |
static int |
TYPE_TILT_DETECTOR
A sensor of this type generates an event each time a tilt event is detected.
|
static int |
TYPE_WAKE_GESTURE
A constant describing a wake gesture sensor.
|
static int |
TYPE_WRIST_TILT_GESTURE
A constant describing a wrist tilt gesture sensor.
|
Modifier and Type | Method and Description |
---|---|
int |
getFifoMaxEventCount() |
int |
getFifoReservedEventCount() |
int |
getHandle() |
int |
getId() |
int |
getMaxDelay()
This value is defined only for continuous and on-change sensors.
|
float |
getMaximumRange() |
int |
getMinDelay() |
String |
getName() |
float |
getPower() |
int |
getReportingMode()
Each sensor has exactly one reporting mode associated with it.
|
String |
getRequiredPermission() |
float |
getResolution() |
String |
getStringType() |
int |
getType() |
UUID |
getUuid()
Do not use.
|
String |
getVendor() |
int |
getVersion() |
boolean |
isAdditionalInfoSupported()
Returns true if the sensor supports sensor additional information API
|
boolean |
isDataInjectionSupported()
Returns true if the sensor supports data injection when the
HAL is set to data injection mode.
|
boolean |
isDynamicSensor()
Returns true if the sensor is a dynamic sensor.
|
boolean |
isWakeUpSensor()
Returns true if the sensor is a wake-up sensor.
|
String |
toString()
Returns a string representation of the object.
|
public static final int TYPE_ACCELEROMETER
See SensorEvent.values
for more details.
public static final String STRING_TYPE_ACCELEROMETER
TYPE_ACCELEROMETER
,
Constant Field Valuespublic static final int TYPE_MAGNETIC_FIELD
See SensorEvent.values
for more details.
public static final String STRING_TYPE_MAGNETIC_FIELD
TYPE_MAGNETIC_FIELD
,
Constant Field Values@Deprecated public static final int TYPE_ORIENTATION
SensorManager.getOrientation()
instead.See SensorEvent.values
for more details.
@Deprecated public static final String STRING_TYPE_ORIENTATION
SensorManager.getOrientation()
instead.TYPE_ORIENTATION
,
Constant Field Valuespublic static final int TYPE_GYROSCOPE
See SensorEvent.values
for more details.
public static final String STRING_TYPE_GYROSCOPE
TYPE_GYROSCOPE
,
Constant Field Valuespublic static final int TYPE_LIGHT
See SensorEvent.values
for more details.
public static final String STRING_TYPE_LIGHT
TYPE_LIGHT
,
Constant Field Valuespublic static final int TYPE_PRESSURE
See SensorEvent.values
for more details.
public static final String STRING_TYPE_PRESSURE
TYPE_PRESSURE
,
Constant Field Values@Deprecated public static final int TYPE_TEMPERATURE
Sensor.TYPE_AMBIENT_TEMPERATURE
instead.@Deprecated public static final String STRING_TYPE_TEMPERATURE
Sensor.STRING_TYPE_AMBIENT_TEMPERATURE
instead.TYPE_TEMPERATURE
,
Constant Field Valuespublic static final int TYPE_PROXIMITY
See SensorEvent.values
for more details.
isWakeUpSensor()
,
Constant Field Valuespublic static final String STRING_TYPE_PROXIMITY
TYPE_PROXIMITY
,
Constant Field Valuespublic static final int TYPE_GRAVITY
See SensorEvent.values
for more details.
public static final String STRING_TYPE_GRAVITY
TYPE_GRAVITY
,
Constant Field Valuespublic static final int TYPE_LINEAR_ACCELERATION
See SensorEvent.values
for more details.
public static final String STRING_TYPE_LINEAR_ACCELERATION
TYPE_LINEAR_ACCELERATION
,
Constant Field Valuespublic static final int TYPE_ROTATION_VECTOR
See SensorEvent.values
for more details.
public static final String STRING_TYPE_ROTATION_VECTOR
TYPE_ROTATION_VECTOR
,
Constant Field Valuespublic static final int TYPE_RELATIVE_HUMIDITY
See SensorEvent.values
for more details.
public static final String STRING_TYPE_RELATIVE_HUMIDITY
TYPE_RELATIVE_HUMIDITY
,
Constant Field Valuespublic static final int TYPE_AMBIENT_TEMPERATURE
See SensorEvent.values
for more details.
public static final String STRING_TYPE_AMBIENT_TEMPERATURE
TYPE_AMBIENT_TEMPERATURE
,
Constant Field Valuespublic static final int TYPE_MAGNETIC_FIELD_UNCALIBRATED
Similar to TYPE_MAGNETIC_FIELD
but the hard iron calibration (device calibration
due to distortions that arise from magnetized iron, steel or permanent magnets on the
device) is not considered in the given sensor values. However, such hard iron bias values
are returned to you separately in the result SensorEvent.values
so you may use them for custom calibrations.
Also, no periodic calibration is performed (i.e. there are no discontinuities in the data stream while using this sensor) and assumptions that the magnetic field is due to the Earth's poles is avoided, but factory calibration and temperature compensation have been performed.
See SensorEvent.values
for more
details.
public static final String STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED
public static final int TYPE_GAME_ROTATION_VECTOR
Identical to TYPE_ROTATION_VECTOR
except that it doesn't
use the geomagnetic field. Therefore the Y axis doesn't
point north, but instead to some other reference, that reference is
allowed to drift by the same order of magnitude as the gyroscope
drift around the Z axis.
In the ideal case, a phone rotated and returning to the same real-world orientation should report the same game rotation vector (without using the earth's geomagnetic field). However, the orientation may drift somewhat over time.
See SensorEvent.values
for more
details.
public static final String STRING_TYPE_GAME_ROTATION_VECTOR
TYPE_GAME_ROTATION_VECTOR
,
Constant Field Valuespublic static final int TYPE_GYROSCOPE_UNCALIBRATED
Similar to TYPE_GYROSCOPE
but no gyro-drift compensation has been performed
to adjust the given sensor values. However, such gyro-drift bias values
are returned to you separately in the result SensorEvent.values
so you may use them for custom calibrations.
Factory calibration and temperature compensation is still applied to the rate of rotation (angular speeds).
See SensorEvent.values
for more
details.
public static final String STRING_TYPE_GYROSCOPE_UNCALIBRATED
TYPE_GYROSCOPE_UNCALIBRATED
,
Constant Field Valuespublic static final int TYPE_SIGNIFICANT_MOTION
It triggers when an event occurs and then automatically disables itself. The sensor continues to operate while the device is asleep and will automatically wake the device to notify when significant motion is detected. The application does not need to hold any wake locks for this sensor to trigger. This is a wake up sensor.
See TriggerEvent
for more details.
isWakeUpSensor()
,
Constant Field Valuespublic static final String STRING_TYPE_SIGNIFICANT_MOTION
TYPE_SIGNIFICANT_MOTION
,
Constant Field Valuespublic static final int TYPE_STEP_DETECTOR
A sensor of this type triggers an event each time a step is taken by the user. The only
allowed value to return is 1.0 and an event is generated for each step. Like with any other
event, the timestamp indicates when the event (here the step) occurred, this corresponds to
when the foot hit the ground, generating a high variation in acceleration. This sensor is
only for detecting every individual step as soon as it is taken, for example to perform dead
reckoning. If you only need aggregate number of steps taken over a period of time, register
for TYPE_STEP_COUNTER
instead. It is defined as a
REPORTING_MODE_SPECIAL_TRIGGER
sensor.
See SensorEvent.values
for more details.
public static final String STRING_TYPE_STEP_DETECTOR
TYPE_STEP_DETECTOR
,
Constant Field Valuespublic static final int TYPE_STEP_COUNTER
A sensor of this type returns the number of steps taken by the user since the last reboot
while activated. The value is returned as a float (with the fractional part set to zero) and
is reset to zero only on a system reboot. The timestamp of the event is set to the time when
the last step for that event was taken. This sensor is implemented in hardware and is
expected to be low power. If you want to continuously track the number of steps over a long
period of time, do NOT unregister for this sensor, so that it keeps counting steps in the
background even when the AP is in suspend mode and report the aggregate count when the AP
is awake. Application needs to stay registered for this sensor because step counter does not
count steps if it is not activated. This sensor is ideal for fitness tracking applications.
It is defined as an REPORTING_MODE_ON_CHANGE
sensor.
See SensorEvent.values
for more details.
public static final String STRING_TYPE_STEP_COUNTER
TYPE_STEP_COUNTER
,
Constant Field Valuespublic static final int TYPE_GEOMAGNETIC_ROTATION_VECTOR
Similar to TYPE_ROTATION_VECTOR
, but using a magnetometer instead of using a
gyroscope. This sensor uses lower power than the other rotation vectors, because it doesn't
use the gyroscope. However, it is more noisy and will work best outdoors.
See SensorEvent.values
for more details.
public static final String STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR
public static final int TYPE_HEART_RATE
The reported value is the heart rate in beats per minute.
The reported accuracy represents the status of the monitor during the reading. See the
SENSOR_STATUS_*
constants in SensorManager
for more details on accuracy/status values. In particular, when the accuracy is
SENSOR_STATUS_UNRELIABLE
or SENSOR_STATUS_NO_CONTACT
, the heart rate
value should be discarded.
This sensor requires permission android.permission.BODY_SENSORS
.
It will not be returned by SensorManager.getSensorsList
nor
SensorManager.getDefaultSensor
if the application doesn't have this permission.
public static final String STRING_TYPE_HEART_RATE
TYPE_HEART_RATE
,
Constant Field Valuespublic static final int TYPE_TILT_DETECTOR
isWakeUpSensor()
,
Constant Field Valuespublic static final String SENSOR_STRING_TYPE_TILT_DETECTOR
TYPE_TILT_DETECTOR
,
Constant Field Valuespublic static final int TYPE_WAKE_GESTURE
Wake gesture sensors enable waking up the device based on a device specific motion.
When this sensor triggers, the device behaves as if the power button was pressed, turning the screen on. This behavior (turning on the screen when this sensor triggers) might be deactivated by the user in the device settings. Changes in settings do not impact the behavior of the sensor: only whether the framework turns the screen on when it triggers.
The actual gesture to be detected is not specified, and can be chosen by the manufacturer of the device. This sensor must be low power, as it is likely to be activated 24/7. Values of events created by this sensors should not be used.
isWakeUpSensor()
,
Constant Field Valuespublic static final String STRING_TYPE_WAKE_GESTURE
TYPE_WAKE_GESTURE
,
Constant Field Valuespublic static final int TYPE_GLANCE_GESTURE
A sensor enabling briefly turning the screen on to enable the user to glance content on screen based on a specific motion. The device should turn the screen off after a few moments.
When this sensor triggers, the device turns the screen on momentarily to allow the user to glance notifications or other content while the device remains locked in a non-interactive state (dozing). This behavior (briefly turning on the screen when this sensor triggers) might be deactivated by the user in the device settings. Changes in settings do not impact the behavior of the sensor: only whether the framework briefly turns the screen on when it triggers.
The actual gesture to be detected is not specified, and can be chosen by the manufacturer of the device. This sensor must be low power, as it is likely to be activated 24/7. Values of events created by this sensors should not be used.
isWakeUpSensor()
,
Constant Field Valuespublic static final String STRING_TYPE_GLANCE_GESTURE
TYPE_GLANCE_GESTURE
,
Constant Field Valuespublic static final int TYPE_PICK_UP_GESTURE
public static final String STRING_TYPE_PICK_UP_GESTURE
TYPE_PICK_UP_GESTURE
,
Constant Field Valuespublic static final int TYPE_WRIST_TILT_GESTURE
public static final String STRING_TYPE_WRIST_TILT_GESTURE
TYPE_WRIST_TILT_GESTURE
,
Constant Field Valuespublic static final int TYPE_DEVICE_ORIENTATION
See SensorEvent.values
for more details.
public static final String STRING_TYPE_DEVICE_ORIENTATION
TYPE_DEVICE_ORIENTATION
,
Constant Field Valuespublic static final int TYPE_POSE_6DOF
TYPE_ROTATION_VECTOR
, with additional delta
translation from an arbitrary reference point.
See SensorEvent.values
for more details.
Can use camera, depth sensor etc to compute output value.
This is expected to be a high power sensor and expected only to be
used when the screen is on.
Expected to be more accurate than the rotation vector alone.public static final String STRING_TYPE_POSE_6DOF
TYPE_POSE_6DOF
,
Constant Field Valuespublic static final int TYPE_STATIONARY_DETECT
SensorEvent.values
for more details.public static final String STRING_TYPE_STATIONARY_DETECT
TYPE_STATIONARY_DETECT
,
Constant Field Valuespublic static final int TYPE_MOTION_DETECT
SensorEvent.values
for more details.public static final String STRING_TYPE_MOTION_DETECT
TYPE_MOTION_DETECT
,
Constant Field Valuespublic static final int TYPE_HEART_BEAT
SensorEvent.values
for more details.public static final String STRING_TYPE_HEART_BEAT
TYPE_HEART_BEAT
,
Constant Field Valuespublic static final int TYPE_DYNAMIC_SENSOR_META
SensorManager.REPORTING_MODE_SPECIAL_TRIGGER
).public static final String STRING_TYPE_DYNAMIC_SENSOR_META
TYPE_DYNAMIC_SENSOR_META
,
Constant Field Valuespublic static final int TYPE_ALL
public static final int TYPE_DEVICE_PRIVATE_BASE
public static final int REPORTING_MODE_CONTINUOUS
SensorManager.registerListener(SensorEventListener, Sensor, int)
. Note: If other
applications are requesting a higher rate, the sensor data might be delivered at faster rates
than requested.public static final int REPORTING_MODE_ON_CHANGE
SensorManager.registerListener(SensorEventListener, Sensor, int)
Note: If other
applications are requesting a higher rate, the sensor data might be delivered at faster rates
than requested.public static final int REPORTING_MODE_ONE_SHOT
SensorManager.requestTriggerSensor(TriggerEventListener, Sensor)
.public static final int REPORTING_MODE_SPECIAL_TRIGGER
public int getReportingMode()
REPORTING_MODE_CONTINUOUS
,
REPORTING_MODE_ON_CHANGE
,
REPORTING_MODE_ONE_SHOT
,
REPORTING_MODE_SPECIAL_TRIGGER
public String getName()
public String getVendor()
public int getType()
public int getVersion()
public float getMaximumRange()
public float getResolution()
public float getPower()
public int getMinDelay()
public int getFifoReservedEventCount()
public int getFifoMaxEventCount()
public String getStringType()
public UUID getUuid()
getId
public int getId()
public String getRequiredPermission()
public int getHandle()
public int getMaxDelay()
public boolean isWakeUpSensor()
Application Processor Power modes
Application Processor(AP), is the processor on which applications run. When no wake lock is held and the user is not interacting with the device, this processor can enter a Suspend mode, reducing the power consumption by 10 times or more.
Non-wake-up sensors
Non-wake-up sensors are sensors that do not wake the AP out of suspend to report data. While
the AP is in suspend mode, the sensors continue to function and generate events, which are
put in a hardware FIFO. The events in the FIFO are delivered to the application when the AP
wakes up. If the FIFO was too small to store all events generated while the AP was in
suspend mode, the older events are lost: the oldest data is dropped to accommodate the newer
data. In the extreme case where the FIFO is non-existent maxFifoEventCount() == 0
,
all events generated while the AP was in suspend mode are lost. Applications using
non-wake-up sensors should usually:
onPause
method. This is the most common case.
Wake-up sensors
In opposition to non-wake-up sensors, wake-up sensors ensure that their data is delivered
independently of the state of the AP. While the AP is awake, the wake-up sensors behave
like non-wake-up-sensors. When the AP is asleep, wake-up sensors wake up the AP to deliver
events. That is, the AP will wake up and the sensor will deliver the events before the
maximum reporting latency is elapsed or the hardware FIFO gets full. See SensorManager.registerListener(SensorEventListener, Sensor, int, int)
for more details.
true
if this is a wake-up sensor, false
otherwise.public boolean isDynamicSensor()
true
if the sensor is a dynamic sensor (sensor added at runtime).SensorManager.DynamicSensorCallback
public boolean isAdditionalInfoSupported()
true
if the sensor supports sensor additional information APISensorAdditionalInfo
public boolean isDataInjectionSupported()
true
if the sensor supports data
injection when the HAL is set in injection mode,
false otherwise.public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())