1. Sensor Overview

Source: Internet
Author: User

Sensor Type

Sensors are an important indicator of the second generation of smartphones. It can be said that Android phones and tablets (excluding TV) on the market now have built-in sensors. Otherwise, many games and applications cannot be used. Not every Android device supports all sensors. Most Android devices only support some sensors. For example, direction sensors (Electronic Compass), gravity sensors (screen flip, racing games, etc ).

Motion sensor

These sensors measure acceleration and rotation angles on three axes (x, y, z. Includes the following sensors.

Accelerometer Sensor

Gravity (gravity) sensor

Gyroscope Sensor

Rotational Vector Sensor

Environment (environmental) sensor

These sensors can measure parameters in different environments, such as air temperature and pressure in the surrounding environment, illumination intensity and humidity. Includes the following sensors.

Humidity (barometer) sensor

Photometer Sensor

Temperature (Thermometer) sensor

Position Sensor

This type of sensor can measure the physical location of the device. Includes the following sensors.

Orientation Sensor

Magnetic (magnetometer) sensor

 

Android sensor framework

The android SDK provides the android sensor framework to access the built-in sensors of the current Android device. ASF provides many classes and interfaces to help us complete various sensor-related tasks. For example, you can use ASF to complete the following tasks.

* Determine which sensors are embedded in the current Android device.

* Determine the technical metrics of a sensor. For example, the maximum measurement range, sensor manufacturer, power requirements, measurement accuracy, and so on. * Obtain the data transmitted from the sensor and define the accuracy of the data returned from the sensor. * Register and deregister sensor event listeners. These listeners are used to monitor sensor changes. Generally, the data returned from the sensor needs to be processed using these listeners.

 

Hardware and software Sensors

ASF allows us to access many sensor types, including hardware-based sensors and software-based sensors. Hardware-based sensors are directly embedded into Android devices in the form of chips. These sensors directly obtain data from external environments, such as acceleration sensors and magnetic field sensors. Software-based sensors are not actually hardware chips, although these sensors reuse much like hardware-based sensors. The data transmitted by software-based sensors also comes from hardware-based sensors, but the data is usually processed twice. That is to say, software-based sensors may return data from one or more hardware-based sensors, and the Android system may use some algorithms to process the data. Therefore, software-based sensors can also be called virtual sensors or synthetic sensors.

ASF-supported Sensors

All constants are defined in the sensor class.

1. type_accelerometer: acceleration sensor (hardware sensor) 2. type_ambient_temperature: temperature sensor (hardware sensor) 3. type_gravity: gravity sensor (hardware or software sensor) 4. type_gyroscope: gyroscope sensor (hardware sensor) 5. type_light: light sensor (hardware sensor) 6. type_linear_acceleration: Linear Acceleration Sensor (hardware or software sensor) 7. type_magnetic_field: Magnetic Field Sensor (hardware sensor) 8. type_orientation: Direction sensor (Software Sensor), data from gravity and magnetic field sensors 9. type_pressure: Pressure Sensor (hardware sensor) 10. type_proximity: proximity sensor (hardware sensor) 11. type_relative_humidity: humidity sensor (hardware sensor) 12. type_rotation_vector: rotating vector sensor (hardware or software sensor)

13. type_temperature: temperature sensor (hardware sensor), which has been replaced by type_ambient_temperature since android4.0 (API level = 14.

 

Main classes and interfaces in ASF@ Sensormanager class: used to create an instance of the sensor service. This class provides many methods for accessing and enumerating sensors, registering and deregistering sensor monitors. It also provides constants related to sensor accuracy, scan frequency, and calibration. @ Nsensor class: provides methods for obtaining sensor technical parameters. Such as version, type, and manufacturer. @ Sensorevent class: The system uses this class to create sensor event objects. This object provides information related to sensor events. Sensor event objects include the original sensor return data, sensor type, data accuracy, and event triggering time. @ Sensoreventlistener: this interface contains two callback methods. When the returned value or precision of the sensor changes, the system calls these two callback methods. Example: Obtain the sensors supported by the current Android device
 1 import java.util.List; 2 import android.app.Activity; 3 import android.hardware.Sensor; 4 import android.hardware.SensorManager; 5 import android.os.Bundle; 6 import android.widget.TextView; 7  8 public class Main extends Activity { 9 10     private TextView tvSensors;11     private SensorManager sensorManager;12 13     @Override14     public void onCreate(Bundle savedInstanceState) {15         super.onCreate(savedInstanceState);16         setContentView(R.layout.main);17 18         tvSensors = (TextView) findViewById(R.id.tvSensors);19         sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);20         List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);21         for (Sensor sensor : sensors) {22             tvSensors.append(sensor.getName() + "\n");23         }24 25     }26 27 }

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.