本文介绍了我可以创建一个新的SensorEvent对象来测试onSensorChanged()函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要测试功能

onSensorChanged (SensorEvent event){..}

在模拟器上.我想创建一个新的SensorEvent对象.我找到了一个不错的链接:

on the emulator.I want to create a new SensorEvent object. I found a nice link:

http://download.java.net/media/java3d/javadoc/1.5.0/com/sun/j3d/utils/behaviors/sensor/SensorEvent.html#SensorEvent%28java.lang.Object,%20int, %20javax.media.j3d.Sensor,%20javax.media.j3d.Transform3D,%20int [],%20int,%20long,%20long%29

http://download.java.net/media/java3d/javadoc/1.5.0/com/sun/j3d/utils/behaviors/sensor/SensorEvent.html#SensorEvent%28java.lang.Object,%20int,%20javax.media.j3d.Sensor,%20javax.media.j3d.Transform3D,%20int[],%20int,%20long,%20long%29

但我不知道如何创建参数

but I don't know how to create argument

Transform3D sensorRead

那么,如何创建Transform3D对象或新的SensorEvent?谢谢.

So, how I create Transform3D object or new SensorEvent one? Thanks.

推荐答案

我认为这不会给您带来任何好处. AFAIK,android.hardware.SensorEvent和com.sun.j3d.utils.behaviors.sensor.SensorEvent之间没有任何关系.

I don't think this will do you any good. AFAIK, there's no relationship between android.hardware.SensorEvent and com.sun.j3d.utils.behaviors.sensor.SensorEvent.

从Android源代码的简要介绍看,似乎根本无法创建自己的SensorEvent对象.如果您问我,这是对Google的严重疏忽.

From a brief look at the Android source code, it looks like there's simply no way to create your own SensorEvent object. This is a serious oversight on Google's part, if you ask me.

这是我的工作.我编写了一个名为sensorChanged(Sensor sensor,float [] values)的方法来完成所有工作,并仅从常规onSensorChanged()方法中调用它.然后,当我想从我的应用程序中测试传感器处理时,我用所需的任何值调用sensorChanged().我可能无法创建SensorEvent对象,但是通过这种方式,我仍然可以测试我的代码.

Here's what I do. I write a method named sensorChanged(Sensor sensor, float[] values) to do all the work, and just call it from the regular onSensorChanged() method. Then, when I want to test sensor handling from within my app, I call sensorChanged() with whatever values I want. I might not be able to create a SensorEvent object, but this way I can still test my code.

这篇关于我可以创建一个新的SensorEvent对象来测试onSensorChanged()函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:03