Can I create a new SensorEvent object to test onSensorChanged() function?

随声附和 提交于 2019-12-23 17:13:12

问题


I want to test the function

onSensorChanged (SensorEvent event){..}

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

but I don't know how to create argument

Transform3D sensorRead

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


回答1:


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.

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.

Edit: 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.



来源:https://stackoverflow.com/questions/8734850/can-i-create-a-new-sensorevent-object-to-test-onsensorchanged-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!