SensorManager
abstract class SensorManager
| kotlin.Any | |
| ↳ | android.hardware.SensorManager |
SensorManager lets you access the device's sensors.
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 TriggerEventListener. Sensor.TYPE_SIGNIFICANT_MOTION is an example of a trigger sensor.
In order to access sensor data at high sampling rates (i.e. greater than 200 Hz for SensorEventListener and greater than SensorDirectChannel.RATE_NORMAL for SensorDirectChannel), apps must declare the android.Manifest.permission#HIGH_SAMPLING_RATE_SENSORS permission in their AndroidManifest.xml file.
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
| Nested classes | |
|---|---|
| abstract |
Used for receiving notifications from the SensorManager when dynamic sensors are connected or disconnected. |
| Constants | |
|---|---|
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int |
Index of the X value in the array returned by |
| static Int |
Index of the Y value in the array returned by |
| static Int |
Index of the Z value in the array returned by |
| static Float |
Gravity (estimate) on the first Death Star in Empire units (m/s^2) |
| static Float |
Earth's gravity in SI units (m/s^2) |
| static Float |
Jupiter's gravity in SI units (m/s^2) |
| static Float |
Mars' gravity in SI units (m/s^2) |
| static Float |
Mercury's gravity in SI units (m/s^2) |
| static Float |
The Moon's gravity in SI units (m/s^2) |
| static Float |
Neptune's gravity in SI units (m/s^2) |
| static Float |
Pluto's gravity in SI units (m/s^2) |
| static Float |
Saturn's gravity in SI units (m/s^2) |
| static Float |
Sun's gravity in SI units (m/s^2) |
| static Float |
Gravity on the island |
| static Float |
Uranus' gravity in SI units (m/s^2) |
| static Float |
Venus' gravity in SI units (m/s^2) |
| static Float |
luminance under a cloudy sky in lux |
| static Float |
luminance at night with full moon in lux |
| static Float |
luminance at night with no moon in lux |
| static Float |
luminance under an overcast sky in lux |
| static Float |
luminance in shade in lux |
| static Float |
luminance of sunlight in lux |
| static Float |
Maximum luminance of sunlight in lux |
| static Float |
luminance at sunrise in lux |
| static Float |
Maximum magnetic field on Earth's surface |
| static Float |
Minimum magnetic field on Earth's surface |
| static Float |
Standard atmosphere, or average sea-level pressure in hPa (millibar) |
| static Int |
Offset to the untransformed values in the array returned by |
| static Int |
Index of the untransformed X value in the array returned by |
| static Int |
Index of the untransformed Y value in the array returned by |
| static Int |
Index of the untransformed Z value in the array returned by |
| static Int |
A constant describing an accelerometer. |
| static Int |
A constant that includes all sensors |
| static Int |
get sensor data as fast as possible |
| static Int |
rate suitable for games |
| static Int |
rate (default) suitable for screen orientation changes |
| static Int |
rate suitable for the user interface |
| static Int |
A constant describing an ambient light sensor See |
| static Int |
A constant describing a magnetic sensor See |
| static Int |
Largest sensor ID |
| static Int |
Smallest sensor ID |
| static Int |
A constant describing an orientation sensor. |
| static Int |
A constant describing an orientation sensor. |
| static Int |
A constant describing a proximity sensor See |
| static Int |
This sensor is reporting data with maximum accuracy |
| static Int |
This sensor is reporting data with low accuracy, calibration with the environment is needed |
| static Int |
This sensor is reporting data with an average level of accuracy, calibration with the environment may improve the readings |
| static Int |
The values returned by this sensor cannot be trusted because the sensor had no contact with what it was measuring (for example, the heart rate monitor is not in contact with the user). |
| static Int |
The values returned by this sensor cannot be trusted, calibration is needed or the environment doesn't allow readings |
| static Int |
A constant describing a temperature sensor See |
| static Int |
A constant describing a Tricorder See |
| static Float |
Standard gravity (g) on Earth. |
| Public methods | |
|---|---|
| open Boolean |
cancelTriggerSensor(listener: TriggerEventListener!, sensor: Sensor!)Cancels receiving trigger events for a trigger sensor. |
| open SensorDirectChannel! |
Create a sensor direct channel backed by shared memory wrapped in HardwareBuffer object. |
| open SensorDirectChannel! |
createDirectChannel(mem: MemoryFile!)Create a sensor direct channel backed by shared memory wrapped in MemoryFile object. |
| open Boolean |
flush(listener: SensorEventListener!)Flushes the FIFO of all the sensors registered for this listener. |
| open static Float |
getAltitude(p0: Float, p: Float)Computes the Altitude in meters from the atmospheric pressure and the pressure at sea level. |
| open static Unit |
getAngleChange(angleChange: FloatArray!, R: FloatArray!, prevR: FloatArray!)Helper function to compute the angle change between two rotation matrices. |
| open Sensor? |
getDefaultSensor(type: Int)Use this method to get the default sensor for a given type. |
| open Sensor? |
getDefaultSensor(type: Int, wakeUp: Boolean)Return a Sensor with the given type and wakeUp properties. |
| open MutableList<Sensor!>! |
getDynamicSensorList(type: Int)Use this method to get a list of available dynamic sensors of a certain type. |
| open static Float |
getInclination(I: FloatArray!)Computes the geomagnetic inclination angle in radians from the inclination matrix I returned by |
| open static FloatArray! |
getOrientation(R: FloatArray!, values: FloatArray!)Computes the device's orientation based on the rotation matrix. |
| open static Unit |
getQuaternionFromVector(Q: FloatArray!, rv: FloatArray!)Helper function to convert a rotation vector to a normalized quaternion. |
| open static Boolean |
getRotationMatrix(R: FloatArray!, I: FloatArray!, gravity: FloatArray!, geomagnetic: FloatArray!)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: |
| open static Unit |
getRotationMatrixFromVector(R: FloatArray!, rotationVector: FloatArray!)Helper function to convert a rotation vector to a rotation matrix. |
| open MutableList<Sensor!>! |
getSensorList(type: Int)Use this method to get the list of available sensors of a certain type. |
| open Int | |
| open Boolean |
Tell if dynamic sensor discovery feature is supported by system. |
| open Unit |
Add a |
| open Unit |
registerDynamicSensorCallback(callback: SensorManager.DynamicSensorCallback!, handler: Handler!)Add a |
| open Boolean |
registerListener(listener: SensorEventListener!, sensor: Sensor!, samplingPeriodUs: Int)Registers a |
| open Boolean |
registerListener(listener: SensorEventListener!, sensor: Sensor!, samplingPeriodUs: Int, handler: Handler!)Registers a |
| open Boolean |
registerListener(listener: SensorEventListener!, sensor: Sensor!, samplingPeriodUs: Int, maxReportLatencyUs: Int)Registers a |
| open Boolean |
registerListener(listener: SensorEventListener!, sensor: Sensor!, samplingPeriodUs: Int, maxReportLatencyUs: Int, handler: Handler!)Registers a |
| open Boolean |
registerListener(listener: SensorListener!, sensors: Int)Registers a listener for given sensors. |
| open Boolean |
registerListener(listener: SensorListener!, sensors: Int, rate: Int)Registers a SensorListener for given sensors. |
| open static Boolean |
remapCoordinateSystem(inR: FloatArray!, X: Int, Y: Int, outR: FloatArray!)Rotates the supplied rotation matrix so it is expressed in a different coordinate system. |
| open Boolean |
requestTriggerSensor(listener: TriggerEventListener!, sensor: Sensor!)Requests receiving trigger events for a trigger sensor. |
| open Unit |
Remove a |
| open Unit |
unregisterListener(listener: SensorEventListener!)Unregisters a listener for all sensors. |
| open Unit |
unregisterListener(listener: SensorEventListener!, sensor: Sensor!)Unregisters a listener for the sensors with which it is registered. |
| open Unit |
unregisterListener(listener: SensorListener!)Unregisters a listener for all sensors. |
| open Unit |
unregisterListener(listener: SensorListener!, sensors: Int)Unregisters a listener for the sensors with which it is registered. |
Constants
DATA_X
static valDATA_X: Int
Deprecated: use Sensor instead.
Index of the X value in the array returned by android.hardware.SensorListener#onSensorChanged
Value: 0DATA_Y
static valDATA_Y: Int
Deprecated: use Sensor instead.
Index of the Y value in the array returned by android.hardware.SensorListener#onSensorChanged
Value: 1DATA_Z
static valDATA_Z: Int
Deprecated: use Sensor instead.
Index of the Z value in the array returned by android.hardware.SensorListener#onSensorChanged
Value: 2GRAVITY_DEATH_STAR_I
static val GRAVITY_DEATH_STAR_I: Float
Gravity (estimate) on the first Death Star in Empire units (m/s^2)
Value: 3.5303614E-7fGRAVITY_EARTH
static val GRAVITY_EARTH: Float
Earth's gravity in SI units (m/s^2)
Value: 9.80665fGRAVITY_JUPITER
static val GRAVITY_JUPITER: Float
Jupiter's gravity in SI units (m/s^2)
Value: 23.12fGRAVITY_MARS
static val GRAVITY_MARS: Float
Mars' gravity in SI units (m/s^2)
Value: 3.71fGRAVITY_MERCURY
static val GRAVITY_MERCURY: Float
Mercury's gravity in SI units (m/s^2)
Value: 3.7fGRAVITY_MOON
static val GRAVITY_MOON: Float
The Moon's gravity in SI units (m/s^2)
Value: 1.6f