Introduction to Android Sensor

Source: Internet
Author: User

1. Sensor Type
Gravity sensor/acceleration sensor (G-sensor)
Light-Sensor)
Temperature Sensing
Direction sensing
Magnetic field,
Closeness

2. How to Implement sensor Programming
A. Obtain the System Service (sensor_service) and return a sensormanager object.
Sensormanager = (sensormanager) getsystemseriver (sensor_service );
B. Get the corresponding sensor type object through the sensormanager object
Sensorobject = sensormanager. getdefasensensor (sensor type );
C. Declare a sensoreventlistener object to listen for the sensor event and reload the onsensorchanged method.
Sensoreventlistener sensorlistener = new sensoreventlistener (){
};
D. register the corresponding sensorservice
Sensormanager. registerlistener (sensorlistener, sensorobject, sensor type );
E. Destroy the corresponding sensorservice
Sensormanager. unregisterlistener (sensorlistener, sensorobject );

F: The sensorlistener interface is a sensor application. Program . It includes two required methods:
The onsensorchanged (INT sensor, float values []) method is called when the sensor value is changed.
This method is only called by the sensor monitored by this application (for more information, see the following ). Parameters of this method include: an integer indicating the changed sensor; an array of floating-point values indicating the sensor data itself. Some sensors only provide one data value, while others provide three floating point values. The direction sensor and the acceleration table sensor both provide three data values.
When the sensor's accuracy changes, the onaccuracychanged (INT sensor, int accuracy) method is called. Parameters include two integers: one representing the sensor and the other representing the new accurate value of the sensor.

 
3. About G-Sensor
The android accelerometer is of the sensor. type_accelerometer type.
Return the value of the accelerometer through Android. Hardware. sensorevent.
The Unit returned by the accelerometer is the unit of acceleration m/s ^ 2 (meter per second). The values in three directions are
Values [0]: X-axis Acceleration
Values [1]: acceleration in Y-axis direction
Values [2]: acceleration in the z-axis direction
The X, Y, and Z directions are defined as the coordinates of the reference system at the bottom right of the horizontally placed mobile phone.

the X direction is the horizontal direction of the mobile phone, and the right direction is positive
the y direction is the horizontal vertical direction of the mobile phone, and the front is positive
the y direction is the vertical direction of the mobile phone space, the direction of the sky is positive, and the direction of the earth is negative
note that due to the inherent gravity acceleration G of the Earth (the value is 9.8 Mb/s ^ 2 ),
in reality, the actual acceleration value should be the return value in the z direction-9.8 m/s ^ 2.
for example, if you throw a mobile phone at the acceleration of 2 Mbit/s ^ 2, then the return value in the z direction is 11.8 Mbit/s ^ 2.
If the mobile phone drops at a 2 Mbit/s ^ 2 acceleration, the return value in the z direction is 7.8 Mbit/s ^ 2.
the preceding restrictions are not imposed on the X and Y directions.

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.