Several sensors supported by Android

Source: Internet
Author: User

1. Accelerometer acceleration, which describes acceleration.

2. Gravity gravity, which is known to everyone.

3. The gyroscope is more powerful for object drop detection. It will be a bit regrettable to develop a game if it is missing. The new type of API level 9 is added.

4. Light sensor. The screen brightness of many Android phones is automatically adjusted according to the sensor array.

5. added the linear_acceleration linear accelerator and API level 9.

6. magnetic_field pole sensor.

7. orientation direction sensor.

8. pressure sensor.

9. proximity distance sensor is useful for turning off the screen backlight after a call.

10. rotation_vector: the rotation vector added by Android 2.3. If we process images in the past, we will find this useful, but it is still helpful for game development.

11. Temperature temperature sensor can obtain the internal temperature of the mobile phone. However, there is a gap between the temperature and the peripheral temperature. After all, the internal temperature of the mobile phone is usually relatively high.

Package COM. hellosensor; import Java. util. list; import android. app. activity; import android. content. context; import android. hardware. sensor; import android. hardware. sensorevent; import android. hardware. sensoreventlistener; import android. hardware. sensormanager; import android. OS. bundle; import android. widget. textview; public class hellosensor extends activity {sensor; private float x, y, z;/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // prepare the UI for displaying information to form final textview tx1 = (textview) findviewbyid (R. id. textview01); // obtain the sensor manager sensormanager Sm = (sensormanager) getsystemservice (context. sensor_service); // obtain the list of all sensors from the sensor manager <Sensor> allsensors = Sm. getsensorlist (sensor. type_all); // display the number of sensors tx1.settext ("detected on this phone" + allsensors. size () + "sensors, they are \ n"); // display the specific information of each sensor for (sensor S: allsensors) {string tempstring = "\ n" + "device name:" + S. getname () + "\ n" + "device version:" + S. getversion () + "\ n" + "supplier:" + S. getvendor () + "\ n"; Switch (S. getType () {Case sensor. type_accelerometer: tx1.settext (tx1.gettext (). tostring () + S. getType () + "accelerometer" + tempstring); break; Case sensor. type_gravity: tx1.settext (tx1.gettext (). tostring () + S. getType () + "Gravity sensor gravity API 9" + tempstring); break; Case sensor. type_gyroscope: tx1.settext (tx1.gettext (). tostring () + S. getType () + "gyroscope sensor gyroscope" + tempstring); break; Case sensor. type_light: tx1.settext (tx1.gettext (). tostring () + S. getType () + "ambient light sensor light" + tempstring); break; Case sensor. type_linear_acceleration: tx1.settext (tx1.gettext (). tostring () + S. getType () + "linear_acceleration API 9" + tempstring); break; Case sensor. type_magnetic_field: tx1.settext (tx1.gettext (). tostring () + S. getType () + "Electromagnetic Field Sensor magnetic field" + tempstring); break; Case sensor. type_orientation: tx1.settext (tx1.gettext (). tostring () + S. getType () + "orientation sensor orientation" + tempstring); break; Case sensor. type_pressure: tx1.settext (tx1.gettext (). tostring () + S. getType () + "Pressure Sensor pressure" + tempstring); break; Case sensor. type_proximity: tx1.settext (tx1.gettext (). tostring () + S. getType () + "distance sensor proximity" + tempstring); break; Case sensor. type_rotation_vector: tx1.settext (tx1.gettext (). tostring () + S. getType () + "rotation vector rotation" + tempstring); break; Case sensor. type_temperature: tx1.settext (tx1.gettext (). tostring () + S. getType () + "temperature sensor temperature" + tempstring); break; default: tx1.settext (tx1.gettext (). tostring () + S. getType () + "unknown sensor" + tempstring); break ;}// displays the sensor's change sensor = Sm on the title. getdefasensensor (sensor. type_accelerometer); sensoreventlistener lsn = new sensoreventlistener () {public void onsensorchanged (sensorevent e) {x = E. values [sensormanager. data_x]; y = E. values [sensormanager. data_y]; Z = E. values [sensormanager. data_z]; settitle ("x =" + (INT) x + "," + "Y =" + (INT) Y + ", "+" z = "+ (INT) z);} public void onaccuracychanged (sensor S, int accuracy) {}}; // register listener, the third parameter is the detection precision SM. registerlistener (LSN, sensor, sensormanager. sensor_delay_game );}}
Related Article

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.