找回密码
 立即注册
SensorTestcodefans传感器SENSOR | android开发 2022-10-27 68 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
Android手机系统中的重力传感器+源码,作者信息:Himi,重力传感器也称为加/速度传感器,源代码编译环境需求SDK1.5(api3)支持。此传感器不仅对玩家回转手机的动作可以检测到,并且会依据回转手机的程度,得到传感器的值也会不同!部分源代码释义:通过服务得到传感器管理对象sm=(SensorManager)MainActivity.ma.getSystemService(Service.SENSOR_SERVICE);sensor=sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);//得到一个重力传感器实例//TYPE_ACCELEROMETER加/速度传感器(重力传感器)类型。//TYPE_ALL描绘一切类型的传感器。//TYPE_GYROSCOPE陀螺仪传感器类型//TYPE_LIGHT光传感器类型//TYPE_MAGNETIC_FIELD稳定磁场传感器类型。//TYPE_ORIENTATION方向传感器类型。//TYPE_PRESSURE描绘一个稳定的压力传感器类型//TYPE_PROXIMITY常量描绘型接近传感器//TYPE_TEMPERATURE温度传感器类型描绘mySensorListener=newSensorEventListener(){@Override//传感器获取值发作改动时在响应此函数publicvoidonSensorChanged(SensorEventevent){//补白1//传感器获取值发作改动,在此管理x=event.values[0];//手机横向翻滚//xgt;0说明当时手机左翻xlt;0右翻y=event.values[1];//手机纵向翻滚//ygt;0说明当时手机下翻ylt;0上翻z=event.values[2];//屏幕的朝向//zgt;0手机屏幕朝上zlt;0手机屏幕朝下arc_x-=x;//补白2arc_y+=y;本资料共包括以下附件:
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
.....太多文件了省略.....

(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)

[下载]14273848265.rar




上一篇:android下Poll投票小程序.源代码
下一篇:《Google+Android开发入门与实践》代码