首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android批改重力感应方向

2012-11-22 
android修改重力感应方向在这里简要的为大家介绍一下我曾经改过android手机重力感应的一点知识。。。首先,大

android修改重力感应方向

在这里简要的为大家介绍一下我曾经改过android手机重力感应的一点知识。。。

      


     首先,大家要android手机重力感应,那么必须得有你自己机器的源代码吧,

    开始在网上找到蛮多资料,但是按其所说并不能实现,后经自己摸索,找到一个能是重力感应与本身相反的方法。

    

   

     要修改android手机重力感应,那么你当然要找到重力感应在那个模块里

    找到frameworks/base/core/java/android/view/WindowOrientationListener.java

    找到其中的nSensorChanged方法,如下:

  public void onSensorChanged(SensorEvent event) {
            // the vector given in the SensorEvent points straight up (towards the sky) under ideal
            // conditions (the phone is not accelerating).  i'll call this upVector elsewhere.
            //xiugai by xxnan 2012-9-13

            本来源码里的event.values[_DATA_X]是正的,

你将它该为负之后就是我们经常看到倒的屏幕

           float x = -event.values[_DATA_X];
            float y = -event.values[_DATA_Y];
            float z = -event.values[_DATA_Z];
           //xiugai by xxnan 2012-9-13
            float magnitude = vectorMagnitude(x, y, z);
            float deviation = Math.abs(magnitude - SensorManager.STANDARD_GRAVITY);

。。。。。。

最后肯定是编译framework的base啦,

生成的就在out下的system/framework/framework.jar


热点排行