参考网址:https://developer.android.com/reference/android/hardware/SensorManager
对SensorManager内容进行摘抄
public abstract class SensorManager
extends Object
| java.lang.Object | |
| ↳ | 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 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) {
}
}
See also:
Summary
Nested classes | |
|---|---|
class | SensorManager.DynamicSensorCallback Used for receiving notifications from the SensorManager when dynamic sensors are connected or disconnected. |
Constants | |
|---|---|
int | AXIS_MINUS_X |
int | AXIS_MINUS_Y |
int | AXIS_MINUS_Z |
int | AXIS_X |
int | AXIS_Y |
int | AXIS_Z |
int | DATA_X This constant was deprecated in API level 15. use |
int | DATA_Y This constant was deprecated in API level 15. use |
int | DATA_Z This constant was deprecated in API level 15. use |
float | GRAVITY_DEATH_STAR_I Gravity (estimate) on the first Death Star in Empire units (m/s^2) |
float | GRAVITY_EARTH Earth's gravity in SI units (m/s^2) |
float | GRAVITY_JUPITER Jupiter's gravity in SI units (m/s^2) |
float | GRAVITY_MARS Mars' gravity in SI units (m/s^2) |
float | GRAVITY_MERCURY Mercury's gravity in SI units (m/s^2) |
float | GRAVITY_MOON The Moon's gravity in SI units (m/s^2) |
float | GRAVITY_NEPTUNE Neptune's gravity in SI units (m/s^2) |
float | GRAVITY_PLUTO Pluto's gravity in SI units (m/s^2) |
float | GRAVITY_SATURN Saturn's gravity in SI units (m/s^2) |
float | GRAVITY_SUN Sun's gravity in SI units (m/s^2) |
float | GRAVITY_THE_ISLAND Gravity on the island |
float | GRAVITY_URANUS Uranus' gravity in SI units (m/s^2) |
float | GRAVITY_VENUS Venus' gravity in SI units (m/s^2) |
float | LIGHT_CLOUDY luminance under a cloudy sky in lux |
float | LIGHT_FULLMOON luminance at night with full moon in lux |
float | LIGHT_NO_MOON luminance at night with no moon in lux |
float | LIGHT_OVERCAST luminance under an overcast sky in lux |
float | LIGHT_SHADE luminance in shade in lux |
float | LIGHT_SUNLIGHT luminance of sunlight in lux |
float | LIGHT_SUNLIGHT_MAX Maximum luminance of sunlight in lux |
float | LIGHT_SUNRISE luminance at sunrise in lux |
float | MAGNETIC_FIELD_EARTH_MAX Maximum magnetic field on Earth's surface |
float | MAGNETIC_FIELD_EARTH_MIN Minimum magnetic field on Earth's surface |
float | PRESSURE_STANDARD_ATMOSPHERE Standard atmosphere, or average sea-level pressure in hPa (millibar) |
int | RAW_DATA_INDEX This constant was deprecated in API level 15. use |
int | RAW_DATA_X This constant was deprecated in API level 15. use |
int | RAW_DATA_Y This constant was deprecated in API level 15. use |
int | RAW_DATA_Z This constant was deprecated in API level 15. use |
int | SENSOR_ACCELEROMETER This constant was deprecated in API level 15. use |
int | SENSOR_ALL This constant was deprecated in API level 15. use |
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 was deprecated in API level 15. use |
int | SENSOR_MAGNETIC_FIELD This constant was deprecated in API level 15. use |
int | SENSOR_MAX This constant was deprecated in API level 15. use |
int | SENSOR_MIN This constant was deprecated in API level 15. use |
int | SENSOR_ORIENTATION This constant was deprecated in API level 15. use |
int | SENSOR_ORIENTATION_RAW This constant was deprecated in API level 15. use |
int | SENSOR_PROXIMITY This constant was deprecated in API level 15. use |
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_NO_CONTACT 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). |
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 was deprecated in API level 15. use |
int | SENSOR_TRICORDER This constant was deprecated in API level 15. use |
float | STANDARD_GRAVITY Standard gravity (g) on Earth. |
Public methods | |
|---|---|
boolean | cancelTriggerSensor(TriggerEventListener listener, Sensor sensor) Cancels receiving trigger events for a trigger sensor. |
SensorDirectChannel | createDirectChannel(MemoryFile mem) Create a sensor direct channel backed by shared memory wrapped in MemoryFile object. |
SensorDirectChannel | createDirectChannel(HardwareBuffer mem) Create a sensor direct channel backed by shared memory wrapped in HardwareBuffer object. |
boolean | flush(SensorEventListener listener) Flushes the FIFO of all the sensors registered for this listener. |
static float | getAltitude(float p0, float p) Computes the Altitude in meters from the atmospheric pressure and the pressure at sea level. |
static void | getAngleChange(float[] angleChange, float[] R, float[] prevR) Helper function to compute the angle change between two rotation matrices. |
Sensor | getDefaultSensor(int type) Use this method to get the default sensor for a given type. |
Sensor | getDefaultSensor(int type, boolean wakeUp) Return a Sensor with the given type and wakeUp properties. |
List<Sensor> | getDynamicSensorList(int type) Use this method to get a list of available dynamic sensors of a certain type. |
static float | getInclination(float[] I) Computes the geomagnetic inclination angle in radians from the inclination matrix I returned by |
static float[] | getOrientation(float[] R, float[] values) Computes the device's orientation based on the rotation matrix. |
static void | getQuaternionFromVector(float[] Q, float[] rv) Helper function to convert a rotation vector to a normalized quaternion. |
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:
|
static void | getRotationMatrixFromVector(float[] R, float[] rotationVector) Helper function to convert a rotation vector to a rotation matrix. |
List<Sensor> | getSensorList(int type) Use this method to get the list of available sensors of a certain type. |
int | getSensors() This method was deprecated in API level 15. This method is deprecated, use |
boolean | isDynamicSensorDiscoverySupported() Tell if dynamic sensor discovery feature is supported by system. |
void | registerDynamicSensorCallback(SensorManager.DynamicSensorCallback callback) Add a |
void | registerDynamicSensorCallback(SensorManager.DynamicSensorCallback callback, Handler handler) Add a |
boolean | registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs) Registers a |
boolean | registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs, int maxReportLatencyUs) Registers a |
boolean | registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs, Handler handler) Registers a |
boolean | registerListener(SensorListener listener, int sensors) This method was deprecated in API level 15. This method is deprecated, use |
boolean | registerListener(SensorListener listener, int sensors, int rate) This method was deprecated in API level 15. This method is deprecated, use |
boolean | registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs, int maxReportLatencyUs, Handler handler) Registers a |
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. |
boolean | requestTriggerSensor(TriggerEventListener listener, Sensor sensor) Requests receiving trigger events for a trigger sensor. |
void | unregisterDynamicSensorCallback(SensorManager.DynamicSensorCallback callback) Remove a |
void | unregisterListener(SensorEventListener listener) Unregisters a listener for all sensors. |
void | unregisterListener(SensorEventListener listener, Sensor sensor) Unregisters a listener for the sensors with which it is registered. |
void | unregisterListener(SensorListener listener) This method was deprecated in API level 15. This method is deprecated, use |
void | unregisterListener(SensorListener listener, int sensors) This method was deprecated in API level 15. This method is deprecated, use |
Inherited methods | |
|---|---|
Constants
AXIS_MINUS_X
Added in API level 3
public static final int AXIS_MINUS_X
see remapCoordinateSystem(float, int, int, float)
Constant Value: 129 (0x00000081)
AXIS_MINUS_Y
Added in API level 3
public static final int AXIS_MINUS_Y
see remapCoordinateSystem(float, int, int, float)
Constant Value: 130 (0x00000082)
AXIS_MINUS_Z
Added in API level 3
public static final int AXIS_MINUS_Z
see remapCoordinateSystem(float, int, int, float)
Constant Value: 131 (0x00000083)
AXIS_X
Added in API level 3
public static final int AXIS_X
see remapCoordinateSystem(float, int, int, float)
Constant Value: 1 (0x00000001)
AXIS_Y
Added in API level 3
public static final int AXIS_Y
see remapCoordinateSystem(float, int, int, float)
Constant Value: 2 (0x00000002)
AXIS_Z
Added in API level 3
public static final int AXIS_Z
see remapCoordinateSystem(float, int, int, float)
Constant Value: 3 (0x00000003)
DATA_X
Added in API level 1
Deprecated in API level 15
public static final int DATA_X
This constant was deprecated in API level 15.
use Sensor instead.
Index of the X value in the array returned by
SensorListener.onSensorChanged(int, float)
Constant Value: 0 (0x00000000)
DATA_Y
Added in API level 1
Deprecated in API level 15
public static final int DATA_Y
This constant was deprecated in API level 15.
use Sensor instead.
Index of the Y value in the array returned by
SensorListener.onSensorChanged(int, float)
Constant Value: 1 (0x00000001)
DATA_Z
Added in API level 1
Deprecated in API level 15
public static final int DATA_Z
This constant was deprecated in API level 15.
use Sensor instead.
Index of the Z value in the array returned by
SensorListener.onSensorChanged(int, float)
Constant Value: 2 (0x00000002)
GRAVITY_DEATH_STAR_I
Added in API level 1
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
GRAVITY_EARTH
Added in API level 1
public static final float GRAVITY_EARTH
Earth's gravity in SI units (m/s^2)
Constant Value: 9.80665
GRAVITY_JUPITER
Added in API level 1
public static final float GRAVITY_JUPITER
Jupiter's gravity in SI units (m/s^2)
Constant Value: 23.12
GRAVITY_MARS
Added in API level 1
public static final float GRAVITY_MARS
Mars' gravity in SI units (m/s^2)
Constant Value: 3.71
GRAVITY_MERCURY
Added in API level 1
public static final float GRAVITY_MERCURY
Mercury's gravity in SI units (m/s^2)
Constant Value: 3.7
GRAVITY_MOON
Added in API level 1
public static final float GRAVITY_MOON
The Moon's gravity in SI units (m/s^2)
Constant Value: 1.6
GRAVITY_NEPTUNE
Added in API level 1
public static final float GRAVITY_NEPTUNE
Neptune's gravity in SI units (m/s^2)
Constant Value: 11.0
GRAVITY_PLUTO
Added in API level 1
public static final float GRAVITY_PLUTO
Pluto's gravity in SI units (m/s^2)
Constant Value: 0.6
GRAVITY_SATURN
Added in API level 1
public static final float GRAVITY_SATURN
Saturn's gravity in SI units (m/s^2)
Constant Value: 8.96
2万+

被折叠的 条评论
为什么被折叠?



