2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
センサー
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Android センサーは、アプリがモバイル デバイスの基盤となる物理センサーにアクセスできるようにします。このセンサーは、センサーの Hardware Abstraction Layer(HAL)である sensors.h によって定義されるデータ提供型仮想デバイスです。
Android センサーとは
Android センサーとは、一連の物理的なセンサー(加速度計、ジャイロスコープ、磁力計、気圧計、湿度センサー、圧力センサー、光センサー、近接センサー、心拍数センサー)からのデータを提供する仮想デバイスです。
カメラ、指紋認証センサー、マイク、タッチ スクリーンは、データを提供する実機のリストには含まれません。これらのデバイスには独自のレポート メカニズムがあります。分離するかどうかは任意ですが、一般に Android センサーは低帯域幅のデータを提供します。たとえば、加速度計では「100 hz x 3 チャンネル」であるのに対し、カメラは「25 hz x 8 MP x 3 チャンネル」、マイクは「44 kHz x 1 チャンネル」となります。
Android では、各種物理センサーをシステム オン チップ(SoC)に接続する方法は定義されません。
- 多くの場合、センサーチップはセンサーハブを介して SoC に接続され、これにより省電力でのデータのモニタリングと処理が実現されます。
- 多くの場合、集積回路間通信(I2C)またはシリアル ペリフェラル インターフェース(SPI)がトランスポート メカニズムとして使用されます。
- 消費電力を削減するために、一部のアーキテクチャは階層化されており、一部の最小の処理はアプリ固有の集積回路で行われ(ASIC - 加速度計チップでのモーション検出など)、それ以上の処理はマイクロコントローラで行われます(センサーハブでのステップ検出など)。
- アーキテクチャは、デバイス メーカーの裁量により、精度、電力、価格、パッケージ サイズなどの特性を考慮して選択されます。詳細については、センサー スタックをご覧ください。
- バッチ処理機能は、電力を最適化するうえで重要な検討項目となります。詳細については、バッチ処理をご覧ください。
Android センサーにはそれぞれの「タイプ」があり、それによってセンサーの動作や提供データがわかります。
- 公式の Android センサータイプは、sensors.h で SENSOR_TYPE_… という名前で定義されます。
- ほとんどのセンサーが、公式のセンサータイプに分類されています。
- これらのタイプは、Android SDK に記載されています。
- これらのタイプのセンサーの動作は、Android 互換性テストスイート(CTS)によりテストされます。
- メーカーが新しい種類の Android デバイス センサーを統合する場合、メーカーは、それを示す独自の一時タイプを定義できます。
- これらのタイプはドキュメントに記載されず、アプリ デベロッパーがそのタイプのセンサーのことを知らないか、ほとんどのデバイスに搭載されていないと考えるため(この特定のメーカーの一部のデバイスにのみ搭載されていると考えるなど)、デベロッパーがそのタイプのセンサーを使用することはほとんどありません。
- これらは CTS によりテストされません。
- Android がこの種類のセンサーに公式のセンサータイプを定義した場合、メーカーは独自の一時タイプの使用を中止し、代わりに公式のタイプを使用する必要があります。公式のタイプを使用することで、より多くのアプリ デベロッパーがそのセンサーを使用するようになります。
- デバイスに搭載されているすべてのセンサーのリストは、HAL 実装によってレポートされます。
- 同じタイプのセンサーが複数存在する場合があります。たとえば、近接センサーが 2 つ存在する場合や、加速度計が 2 つ存在する場合があります。
- ほとんどのアプリは、特定のタイプにつきセンサーを 1 つだけリクエストします。たとえば、デフォルトの加速度計をリクエストするアプリは、リスト内の最初の加速度計を取得します。
- センサーは通常、ウェイクアップと非ウェイクアップのペアで定義されます。両センサーは、同じタイプを共有しますが、ウェイクアップ特性が異なります。
Android センサーは、データを一連のセンサー イベントとして提供します。
各イベントには次のものが含まれます。
レポートされるデータの解釈は、センサータイプによって異なります。各センサータイプのレポート対象データの詳細については、センサータイプの定義をご覧ください。
既存のドキュメント
デベロッパー向け
- 概要
- SDK リファレンス
- スタック オーバーフローとチュートリアルのウェブサイト
- センサーのドキュメントの中には、情報が不足しているものもありました。そのためデベロッパーは Stack Overflow などの Q&A ウェブサイトで情報を見つけていました。
- チュートリアル ウェブサイトもいくつか存在しますが、バッチ処理、大きなモーション、ゲーム回転ベクトルなどの最新の機能は扱われていません。
- これらの外部サイトの情報は必ずしも正しいとは限りません。また、他のドキュメントが必要となる場合もあります。
メーカー向け
- 概要
- Hardware Abstraction Layer(HAL)
- Android CDD(互換性定義ドキュメント)
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-19 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-19 UTC。"],[],[],null,["# Sensors\n\nAndroid sensors give applications access to a mobile device's underlying\nphysical sensors. They are data-providing virtual devices defined by [sensors.h](https://android.googlesource.com/platform/hardware/libhardware/+/android16-release/include/hardware/sensors.h), the sensor Hardware Abstraction Layer (HAL).\n\nWhat are Android sensors?\n-------------------------\n\nAndroid sensors are virtual devices that provide data coming from a set of\nphysical sensors: accelerometers, gyroscopes, magnetometers, barometer, humidity,\npressure, light, proximity and heart rate sensors.\n\nNot included in the list of physical devices providing data are camera,\nfingerprint sensor, microphone, and touch screen. These devices have their own\nreporting mechanism; the separation is arbitrary, but in general, Android sensors\nprovide lower bandwidth data. For example, \"100hz x 3 channels\" for an\naccelerometer versus \"25hz x 8 MP x 3 channels\" for a camera or \"44kHz x 1\nchannel\" for a microphone.\n\nAndroid does not define how the different physical sensors are connected\nto the system on chip (SoC).\n\n- Often, sensor chips are connected to the SoC through a [sensor hub](/docs/core/interaction/sensors/sensor-stack#sensor_hub), allowing some low-power monitoring and processing of the data.\n- Often, Inter-Integrated Circuit (I2C) or Serial Peripheral Interface (SPI) is used as the transport mechanism.\n- To reduce power consumption, some architectures are hierarchical, with some minimal processing being done in the application-specific integrated circuit (ASIC - like motion detection on the accelerometer chip), and more is done in a microcontroller (like step detection in a sensor hub).\n- It is up to the device manufacturer to choose an architecture based on accuracy, power, price and package-size characteristics. See [Sensor stack](/docs/core/interaction/sensors/sensor-stack) for more information.\n- Batching capabilities are an important consideration for power optimization. See [Batching](/docs/core/interaction/sensors/batching) for more information.\n\nEach Android sensor has a \"type\" representing how the sensor behaves and\nwhat data it provides.\n\n- The official Android [Sensor\n types](/docs/core/interaction/sensors/sensor-types) are defined in [sensors.h](https://android.googlesource.com/platform/hardware/libhardware/+/android16-release/include/hardware/sensors.h) under the names SENSOR_TYPE_...\n - The vast majority of sensors have an official sensor type.\n - Those types are documented in the Android SDK.\n - Behavior of sensors with those types are tested in the Android Compatibility Test Suite (CTS).\n- If a manufacturer integrates a new kind of sensor on an Android device, the manufacturer can define its own temporary type to refer to it.\n - Those types are undocumented, so application developers are unlikely to use them, either because they don't know about them, or know that they are rarely present (only on some devices from this specific manufacturer).\n - They are not tested by CTS.\n - Once Android defines an official sensor type for this kind of sensor, manufacturers must stop using their own temporary type and use the official type instead. This way, the sensor will be used by more application developers.\n- The list of all sensors present on the device is reported by the HAL implementation.\n - There can be several sensors of the same type. For example, two proximity sensors or two accelerometers.\n - The vast majority of applications request only a single sensor of a given type. For example, an application requesting the default accelerometer will get the first accelerometer in the list.\n - Sensors are often defined by [wake-up](/docs/core/interaction/sensors/suspend-mode#wake-up_sensors) and [non-wake-up](/docs/core/interaction/sensors/suspend-mode#non-wake-up_sensors) pairs, both sensors sharing the same type, but differing by their wake-up characteristic.\n\nAndroid sensors provide data as a series of sensor events.\n\nEach [event](/docs/core/interaction/sensors/hal-interface#sensors_event_t)\ncontains:\n\n- a handle to the sensor that generated it\n- the timestamp at which the event was detected or measured, based on [`SystemClock.elapsedRealtimeNanos()`](https://developer.android.com/reference/android/os/SystemClock#elapsedRealtimeNanos())\n- and some data\n\nThe interpretation of the reported data depends on the sensor type. See\nthe [sensor type](/docs/core/interaction/sensors/sensor-types)\ndefinitions for details on what data is reported for each sensor type.\n\nExisting documentation\n----------------------\n\n### Targeted at developers\n\n- Overview\n - \u003chttps://developer.android.com/guide/topics/sensors/sensors_overview.html\u003e\n- SDK reference\n - \u003chttps://developer.android.com/reference/android/hardware/SensorManager\u003e\n - \u003chttps://developer.android.com/reference/android/hardware/SensorEventListener\u003e\n - \u003chttps://developer.android.com/reference/android/hardware/SensorEvent\u003e\n - \u003chttps://developer.android.com/reference/android/hardware/Sensor\u003e\n- Stack Overflow and tutorial websites\n - Because sensors documentation was sometimes lacking, developers resorted to Q\\&A websites like Stack Overflow to find answers.\n - Some tutorial websites exist as well, but do not cover the latest features like batching, significant motion and game rotation vectors.\n - The answers over there are not always right, and show where more documentation is needed.\n\n### Targeted at manufacturers\n\n- Overview\n - This [Sensors](/docs/core/interaction/sensors) page and its sub-pages.\n- Hardware abstraction layer (HAL)\n - [/platform/hardware/libhardware/+/android16-release/include/hardware/sensors.h](https://android.googlesource.com/platform/hardware/libhardware/+/android16-release/include/hardware/sensors.h)\n - Also known as \"sensors.h\"\n - The source of truth. First document to be updated when new features are developed.\n- Android CDD (Compatibility Definition Document)\n - [/compatibility/android-cdd.pdf](/static/docs/compatibility/android-cdd.pdf)\n - See sections relative to sensors.\n - The CDD is lenient, so satisfying the CDD requirements is not enough to ensure high quality sensors."]]