Introduction to Sensors

介绍传感器


The Android sensor framework lets you access many types of sensors. Some of these sensors

arehardware-based and some are software-based. Hardware-based sensors are physical components builtinto a handset or tablet device. They derive their data by directly measuring specific environmentalproperties, such as acceleration, geomagnetic field strength, or angular change. Software-basedsensors are not physical devices, although they mimic hardware-based sensors. Software-based sensorsderive their data from one or more of the hardware-based sensors and are sometimes called virtualsensors or synthetic sensors. The linear acceleration sensor and the gravity sensor are examples ofsoftware-based sensors.

Android sensor framework 让你使用多种传感器。有基于硬件和基于软件的。基于硬件的传感器是内置于设备中的物理组件。它们直接测量具体的环境属性来得出数据,例如加速度,地磁场强度,或者角的变化。基于软件的传感器你不是物理设备,尽管它们模拟硬件传感器。软件探测器通过一个或者多个硬件传感器来得出数据,有时称为虚拟传感器或者合成传感器。线性加速度传感器和重力传感器是软件传感器的例子。

Table 1 summarizes the sensors that are supported by the Androidplatform.

表1 总结了android 平台支持的传感器。

Few Android-powered devices have every type of sensor. For example, most handset devices andtablets have an accelerometer and a magnetometer, but fewer devices havebarometers or thermometers. Also, a device can have more than one sensor of a given type. Forexample, a device can have two gravity sensors, each one having a different range.

少有android 设备每种传感器都有。例如,大部分手机设备和平板有一个加速计和一个磁力计,但是较少设备有气压计或温度计。一个设备也可以有一个以上的同类传感器,如果可以用两个不同范围的重力传感器。

Table 1. Sensor types supported by the Android platform.

表1。Android 平台支持的传感器种类。

SensorTypeDescriptionCommon UsesTYPE_ACCELEROMETERHardware

Measures the acceleration force inm/s2 that is applied to a device onall three physical axes (x, y, and z), including the force of gravity.

测量在设备的三个轴的加速度,单位 m/s2 ,包括重力加速度

Motion detection (shake, tilt, etc.).

运动检测

TYPE_AMBIENT_TEMPERATUREHardware

Measures the ambient room temperature in degrees Celsius (°C). See note below.

测量室温,单位摄氏度(°C)

Monitoring air temperatures.

监视空气温度

TYPE_GRAVITYSoftware or Hardware

Measures the force of gravity in m/s2 that is applied to a device on all three physical axes (x, y, z).

测量在设备三个轴的重力加速度,单位m/s2 。

Motion detection (shake, tilt, etc.).TYPE_GYROSCOPEHardware

Measures a device's rate of rotation in rad/s around each of the threephysical axes (x, y, and z).

测量在设备三个轴上的角速度。单位rad/s

Rotation detection (spin, turn, etc.).

旋转检测

TYPE_LIGHTHardware

Measures the ambient light level (illumination) in lx.

测试环境亮度级,单位 lx

Controlling screen brightness.

控制屏幕亮度

TYPE_LINEAR_ACCELERATIONSoftware or Hardware

Measures the acceleration force in m/s2 that isapplied to a device

on all three physical axes (x, y, and z), excluding the force of gravity.

测量在设备三轴上的加速度,排除了重力。

Monitoring acceleration along a single axis.

检测一个轴上的加速度

TYPE_MAGNETIC_FIELDHardware

Measures the ambient geomagnetic field for all three physical axes (x, y, z) inμT.

测量三轴的地磁场,单位μT

Creating a compass.

创建一个罗盘

TYPE_ORIENTATIONSoftware

Measures degrees of rotation that a device makes around all three physical axes (x, y, z).As of API level 3 you can obtain the inclination matrix and rotation matrix for a device by using the gravity sensor and the geomagnetic field sensor in conjunction with the getRotationMatrix() method.

测量设备绕三轴转的旋转度。

Determining device position.TYPE_PRESSUREHardwareMeasures the ambient air pressure in hPa or mbar.测量气压
Monitoring air pressure changes.TYPE_PROXIMITYHardwareMeasures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a person's ear.Phone position during a call.TYPE_RELATIVE_HUMIDITYHardwareMeasures the relative ambient humidity in percent (%).Monitoring dewpoint, absolute, and relative humidity.TYPE_ROTATION_VECTORSoftware or HardwareMeasures the orientation of a device by providing the three elements of the device's rotation vector.Motion detection and rotation detection.TYPE_TEMPERATUREHardwareMeasures the temperature of the device in degrees Celsius (°C). This sensorimplementation varies across devices andthis sensor was replaced with the TYPE_AMBIENT_TEMPERATURE sensor inAPI Level 14Monitoring temperatures.