重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
You can access these sensors and acquire raw sensor data by using the Android sensor framework.
The sensor framework is part of the android.hardware
package and includes the following
classes and interfaces:
创新互联成立与2013年,先为临颍等服务建站,临颍等地企业,进行企业商务咨询服务。为临颍企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
你可以用android sensor framework 使用这些传感器里获得原始传感数据。这个 sensor framework 是 android.hardware 包的一部分,包括以下类和接口:
SensorManager
You can use this class to create an instance of the sensor service. This class provides various methods for accessing and listing sensors, registering and unregistering sensor event listeners, and acquiring orientation information. This class also provides several sensor constants that are used to report sensor accuracy, set data acquisition rates, and calibrate sensors.
用这个类来创建 sensor service 的实例。这个类提供多个方法用来使用和列举 snesors,注册和注销 sensor event listeners,获取定位消息。这个类也提供几个 sensor 常量用于报告 sensor 精度,设置数据采集速率,和校准探测器。
Sensor
You can use this class to create an instance of a specific sensor. This class provides various methods that let you determine a sensor's capabilities.
用这个类来创建一个 sensor 实例。这个类提供多个方法来让你确定一个 sensor 的功能。
SensorEvent
The system uses this class to create a sensor event object, which provides information about a sensor event. A sensor event object includes the following information: the raw sensor data, the type of sensor that generated the event, the accuracy of the data, and the timestamp for the event.
用这个类创建 sensor event object,提供关于一个sensor event的信息。一个sensor event object 包括以下信息:原始传感器数据,产生event的sensor的类别,数据的精度,event的时间戳。
SensorEventListener
You can use this interface to create two callback methods that receive notifications (sensor events) when sensor values change or when sensor accuracy changes.
可用这个接口创建两个回调方法来接收通知(sensor 事件)当 sensor 值改变或者当 sensor 精度改变。
In a typical application you use these sensor-related APIs to perform two basic tasks:
你可以用这些 传感器相关的API完成两个基本任务:
Identifying sensors and sensor capabilities
识别传感器及其功能
Identifying sensors and sensor capabilities at runtime is useful if your application has features that rely on specific sensor types or capabilities. For example, you may
want to identify all of the sensors that are present on a device and disable any application features that rely on sensors that are not present. Likewise, you may want to identify all of the sensors of a given type so you can choose the sensor implementation that has the optimum performance for your application.
在运行时识别传感器及其功能在你的应用需要依赖某个传感器类别或者功能时非常有用。例如,你可能想识别设备上所有的传感器然后在应用中关闭没有的传感器的特性。同样地,你可能想识别一特定类别的所有传感器然后选择性能对你的应用最优的。
Monitor sensor events
监测传感器事件
Monitoring sensor events is how you acquire raw sensor data. A sensor event occurs every time a sensor detects a change in the parameters it is measuring. A sensor event provides you with four pieces of information: the name of the sensor that triggered the event, the timestamp for the event, the accuracy of the event, and the raw sensor data that triggered the event.
监测传感器事件是你获取原始探测数据的方式。每当一个传感器在测量时探测到某个参数改变,一个sensor 事件就发生了。一个 sensor 事件提供四条消息:触发事件的sensor名称,事件的时间戳,事件的精度,触发事件的原始探测数据。
传感器的可用性
While sensor availability varies from device to device, it can also vary between Android versions. This is because the Android sensors have been introduced over the course of several platform releases. For example, many sensors were introduced in Android 1.5 (API Level 3), but some were not implemented and were not available for use until Android 2.3 (API Level 9). Likewise, several sensors were introduced in Android 2.3 (API Level 9) and Android 4.0 (API Level 14). Two sensors have been deprecated and replaced by newer, better sensors.
Table 2 summarizes the availability of each sensor on a platform-by-platform basis. Only four platforms are listed because those are the platforms that involved sensor changes. Sensors that are listed as deprecated are still available on subsequent platforms (provided the sensor is present on a device), which is in line with Android's forward compatibility policy.
Table 2.Sensor availability by platform.
Sensor | Android 4.0 (API Level 14) | Android 2.3 (API Level 9) | Android 2.2 (API Level 8) | Android 1.5 (API Level 3) |
---|---|---|---|---|
TYPE_ACCELEROMETER | Yes | Yes | Yes | Yes |
TYPE_AMBIENT_TEMPERATURE | Yes | n/a | n/a | n/a |
TYPE_GRAVITY | Yes | Yes | n/a | n/a |
TYPE_GYROSCOPE | Yes | Yes | n/a1 | n/a1 |
TYPE_LIGHT | Yes | Yes | Yes | Yes |
TYPE_LINEAR_ACCELERATION | Yes | Yes | n/a | n/a |
TYPE_MAGNETIC_FIELD | Yes | Yes | Yes | Yes |
TYPE_ORIENTATION | Yes2 | Yes2 | Yes2 | Yes |
TYPE_PRESSURE | Yes | Yes | n/a1 | n/a1 |
TYPE_PROXIMITY | Yes | Yes | Yes | Yes |
TYPE_RELATIVE_HUMIDITY | Yes | n/a | n/a | n/a |
TYPE_ROTATION_VECTOR | Yes | Yes | n/a | n/a |
TYPE_TEMPERATURE | Yes2 | Yes | Yes | Yes |
1This sensor type was added in Android 1.5 (API Level 3), but it was not available for use until Android 2.3 (API Level 9).
2This sensor is available, but it has been deprecated.