您好,登錄后才能下訂單哦!
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:
你可以用android sensor framework 使用這些傳感器里獲得原始傳感數(shù)據(jù)。這個 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.
用這個類來創(chuàng)建 sensor service 的實例。這個類提供多個方法用來使用和列舉 snesors,注冊和注銷 sensor event listeners,獲取定位消息。這個類也提供幾個 sensor 常量用于報告 sensor 精度,設(shè)置數(shù)據(jù)采集速率,和校準探測器。
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.
用這個類來創(chuàng)建一個 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.
用這個類創(chuàng)建 sensor event object,提供關(guān)于一個sensor event的信息。一個sensor event object 包括以下信息:原始傳感器數(shù)據(jù),產(chǎn)生event的sensor的類別,數(shù)據(jù)的精度,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.
可用這個接口創(chuàng)建兩個回調(diào)方法來接收通知(sensor 事件)當 sensor 值改變或者當 sensor 精度改變。
In a typical application you use these sensor-related APIs to perform two basic tasks:
你可以用這些 傳感器相關(guān)的API完成兩個基本任務(wù):
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.
在運行時識別傳感器及其功能在你的應(yīng)用需要依賴某個傳感器類別或者功能時非常有用。例如,你可能想識別設(shè)備上所有的傳感器然后在應(yīng)用中關(guān)閉沒有的傳感器的特性。同樣地,你可能想識別一特定類別的所有傳感器然后選擇性能對你的應(yīng)用最優(yōu)的。
Monitor sensor events
監(jiān)測傳感器事件
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.
監(jiān)測傳感器事件是你獲取原始探測數(shù)據(jù)的方式。每當一個傳感器在測量時探測到某個參數(shù)改變,一個sensor 事件就發(fā)生了。一個 sensor 事件提供四條消息:觸發(fā)事件的sensor名稱,事件的時間戳,事件的精度,觸發(fā)事件的原始探測數(shù)據(jù)。
傳感器的可用性
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.
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 |
1 This 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).
2 This sensor is available, but it has been deprecated.
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。