欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

android修改重力感应方向

发布时间:2023/12/15 编程问答 47 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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


总结

以上是生活随笔为你收集整理的android修改重力感应方向的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。