(Gravity sensor source code in Android mobile phone system. Author information: Himi. Gravity sensor is also called acceleration/speed sensor. The source code compilation environment needs SDK1.5 (api3) support. This sensor can not only detect the player's action of turning the mobile phone, but also obtain different sensor values according to the degree of turning the mobile phone! Part of the source code definition: get the sensor management object sm=(SensorManager) MainActivity. ma. getSystemService (Service. SENSOR_SERVICE) through the service; sensor=sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);// Get a gravity sensor instance//TYPE_ ACCELEROMETER acceleration/velocity sensor (gravity sensor) type// TYPE_ ALL depicts all types of sensors// TYPE_ GYROSCOPE Gyro Sensor Type//TYPE_ LIGHT light sensor type//TYPE_ MAGNETIC_ FIELD stabilized magnetic field sensor type// TYPE_ ORIENTATION Direction sensor type// TYPE_ PRESSURE depicts a stable pressure sensor type//TYPE_ PROXIMITY Constant Descriptive Proximity Sensor//TYPE_ TEMPERATURE temperature sensor type description mySensorListener=newSensorEventListener() {@ Override//When the sensor gets a value change, respond to this function publicvoid onSensorChanged (SensorEventevent) {//fill in 1//When the sensor gets a value change, manage x=event. values [0] here;//The phone rolls horizontally//xgt; 0 indicates that the phone turns left xlt; 0 turns right y=event. values [1] ;// The phone rolls vertically//ygt; 0 indicates that the mobile phone was turned down ylt at that time; 0 up z=event values[2];// Orientation of the screen//zgt; 0 Phone screen up zlt; 0 Phone screen down arc_ x-=x;// Fill in 2arc_ y =y; This document includes the following annexes:
codefans\SensorTest\bin\com\himi\MainActivity.class
codefans\SensorTest\bin\com\himi\MySurfaceView$1.class
codefans\SensorTest\bin\com\himi\MySurfaceView.class
codefans\SensorTest\bin\com\himi\R$attr.class
codefans\SensorTest\bin\com\himi\R$drawable.class
codefans\SensorTest\bin\com\himi\R$layout.class
codefans\SensorTest\bin\com\himi\R$string.class
codefans\SensorTest\bin\com\himi\R.class
codefans\SensorTest\bin\classes.dex
codefans\SensorTest\bin\resources.ap_
codefans\SensorTest\bin\SensorTest.apk
codefans\SensorTest\gen\com\himi\R.java
codefans\SensorTest\res\drawable-hdpi\icon.png
codefans\SensorTest\res\drawable-ldpi\icon.png
codefans\SensorTest\res\drawable-mdpi\icon.png
codefans\SensorTest\res\layout\main.xml
codefans\SensorTest\res\values\strings.xml
codefans\SensorTest\src\com\himi\MainActivity.java
codefans\SensorTest\src\com\himi\MySurfaceView.java
codefans\SensorTest\.classpath
codefans\SensorTest\.project
codefans\SensorTest\AndroidManifest.xml
codefans\SensorTest\default.properties
..... Too many files omitted)