Android Sensor Overview-android learning Journey (vii)

Source: Internet
Author: User

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)

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.