Sensor overview
Sensors are one of the important symbols of the second generation of smartphones. Many phones and tablets are now built-in with sensors (except TV). The Android SDK supports a number of more than 10 sensors, but the phone only supports a subset. such as the direction sensor (electronic compass) and the gravity sensor (screen flipping).
Roughly divided into three categories
- Motion sensor
- Environmental sensors '
- Position sensor
Motion sensor
These sensors measure acceleration and angle of rotation on three axes (x, Y, z). Several sensors are included.
-Acceleration Sensor
-Gravity sensor
-Gyro Sensor
-Rotation vector sensor
Environmental sensors
- Humidity sensor '
- Light sensor
- Temperature sensor
Position sensor
- Direction sensor
- Magnetic sensors
Android Sensor Framework
Android SDK built-in Android sensor Framework, can access the Android device built-in sensors, ASF provides many classes and interfaces that can help us after that much work.
-Identify second-level sensors built into Android devices
-Determine the technical specifications of a sensor, such as measuring range, accuracy, manufacturer and accuracy
-Get back data from sensors
-Register and note sensor monitoring events to monitor changes in the sensor, usually returning data to be done through these listeners.
Hardware sensors and software sensors
ASF allows us to access a number of sensor types, with hardware-based and also given to even software,
Hardware sensors are hardware-based sensors that are embedded directly into the Android device in the form of a chip that obtains data from the outside, such as acceleration sensors and magnetic field sensors.
Software sensors are not hardware-based, and the data returned is essentially based on two processing of hardware-based sensors, possibly from one or more hardware sensors, and possibly using a specific algorithm to process the data.
ASF-Supported sensors
Main classes and interfaces in ASF
- Sensor Manager: Used to create an instance of the Sonsor service. This class provides a number of methods for accessing and enumerating sensors, registering and unregistering sensors. It also provides the amount of sensor accuracy, scanning frequency, and correction.
- Sensor class: Provides a number of methods for acquiring sensor technical parameters. such as version and type, manufacturer.
- Sensorevent class: Create a sensor time object, time can pass sensor-related data, type, precision and trigger time.
- Sensoreventlistene interface: When the return value or accuracy of the sensor is changed, the system is called.
Get the sensor instances supported by your Android device
The code is as follows;
Public class mainactivity extends Activity { PrivateTextView Tvsensor;PrivateSensormanager Sensormanager;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.main); Tvsensor = (TextView) Findviewbyid (r.id.tvsensor); Sensormanager = (Sensormanager) getsystemservice (Sensor_service); list<sensor> list = Sensormanager.getsensorlist (Sensor.type_all); for(Sensor sensor:list) {Tvsensor.append (Sensor.getname () +"\ n"); } }}
:
Android Sensor Overview-android learning Journey (vii)