Detailed explanation of calling method of light sensor in Android programming

This paper describes the calling method of light sensor in Android programming. Share with you for your reference, as follows:

1. Activity if you want to use sensors, you must implement the sensoreventlistener interface

2. Get the sensor manager

3. Use the sensormanager.registerlistener method to register the specified sensor

4. Complete other specific work in the onsensorchanged and onaccuracychanged methods in the sensoreventlistener interface

Sensor type

Acceleration sensor (sensor. Type_accelerometer) magnetic field sensor (sensor. Type_magnetic_fly) light sensor (sensor. Type_light) direction sensor (type_orientation)

Values value

Acceleration sensor values [0]: acceleration values along the x-axis [1]: acceleration values along the y-axis [2]: acceleration along the z-axis, that is, gravity acceleration

The three elements in the gravity sensor values array represent the gravity of the x-axis, Y-axis and z-axis respectively

In the light sensor values array, only the first element values [0] is meaningful, indicating the intensity of the light, and the maximum value is 120000.0f

Gyro scope values, which represent the angular velocity of rotation of X, y and Z axes respectively

Orientation values [0]: this value represents the orientation, that is, the angle at which the mobile phone rotates around the z-axis. 0 represents north, 90 represents East, 180 represents South, 270 represents west values [1]: it represents the inclination. When the x-axis tilts, this value changes, - 180 < = vaules [1] < = 180 values [2]: it represents the rolling angle along the y-axis, - 90 < = values [2] < = 90

In Android 2.3 SDK, sensor.type is not recommended_ Orientation, values [0], and sometimes exceptions occur. Officials recommend using sensormanager. Getorientaion to get the right direction

Value update speed

SENSOR_ DELAY_ Fastest: get sensor data at the fastest speed_ DELAY_ Game: suitable for obtaining sensor data in the game_ DELAY_ Normal: obtain sensor data at a normal speed_ DELAY_ UI: suitable for obtaining data in UI space

For more Android related content, readers who are interested can view the topics on this site: summary of Android basic component usage, summary of Android view skills, summary of Android layout skills, summary of Android resource operation skills, summary of Android file operation skills, introduction and advanced tutorial of Android development Activity operation skills summary of Android programming and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>