Listing available sensors – an introduction to the Android Sensor Framework
Android includes support for hardware sensors using the Android Sensor Framework. The framework includes the following classes and interfaces:
SensorManager
Sensor
SensorEventListener
SensorEvent
Most Android devices include hardware sensors, but they vary greatly between different manufacturers and models. If your application utilizes sensors, you have two choices:
- Specify the sensor in the Android Manifest
- Check for the sensor at runtime
To specify your application uses a sensor, include the <uses-feature>
declaration in the Android Manifest. Here is an example requiring a compass to be available:
<uses-feature android:name="android.hardware.sensor.compass" android:required="true"/>
If your application utilizes the compass, but does not require it to function, you should set android:required="false"
instead; otherwise your application will not be available to install from Google Play.
Sensors are grouped into...