Introduction to this section:
As mentioned at the end of the previous section, since the author hasn't had much experience with sensors, this section will simply introduce the remaining commonly used sensors as general knowledge. We'll study them in depth when we need them later~
1. Magnetic field sensor
Function: This sensor is mainly used to read changes in the magnetic field around the phone.
Collected sensor values: There are three, namely: the magnetic field values in the X, Y, and Z axis directions.
Unit: T, microtesla
Obtaining the sensor:Sensor.TYPE_MAGNETIC_FIELD
2. Proximity sensor
Function: Used to sense the distance between the phone and the human body. The most common use is during phone calls: when the face is close to the screen, the screen turns off; when the face moves away from the screen by a certain distance, the screen lights up again. This prevents the face from accidentally touching the hang-up button during the call and causing the call to be interrupted. We can use this sensor to create interactive apps~
Collected sensor values: There is one, the distance between the object and the device.
Unit: cm, centimeter
Obtaining the sensor:Sensor.TYPE_PROXIMITY
Other:
① There may be two types of proximity sensors: one can directly give the distance, while the other only indicates near or far! That is, it only returns two values, 0.0 or the maximum value! We can determine this by comparing whether the resolution and the maximum value are equal! If they are equal, it is the latter; if not, it is the former!
② Call the sensor.getResolution() method to get the resolution, and getMaximumRange() to get the maximum value!
3. Light sensor
Function: Used to read the light value, i.e., light intensity.
Collected sensor values: There is one, the brightness value.
Unit: lux, 1 lumen per square meter area, that is 1 lux. The maximum value is 120000.0f. Android divides light intensity into different levels; you can check the SensorManager class yourself~
Obtaining the sensor:Sensor.TYPE_LIGHT
4. Pressure sensor
Function: Used to measure atmospheric pressure, often used to measure altitude.
Collected sensor values: There is one, the atmospheric pressure value.
Unit: hPa, hectopascal
Obtaining the sensor:Sensor.TYPE_PRESSURE
5. Temperature sensor
Function: Measure the temperature inside the phone or the temperature of the external environment.
Collected sensor values: There is one, the temperature value.
Unit: ℃, Celsius
Obtaining the sensor:Sensor.TYPE_TEMPERATURE(Phone internal)/TYPE_AMBIENT_TEMPERATURE(Phone external)
6. Sensor simulation tool - SensorSimulator
As the title suggests, when our real device does not have a certain sensor but we still need to develop, see the following article for specific usage:Sensor simulation tool on Android devices: SensorSimulator
Summary of this section:
Okay, this section should be the most "chicken rib" one in the beginner tutorial series. I didn't really want to write it, but I'll write it anyway. Just know what's above~ As always, we'll study it in depth when we need it later. Thanks.
