Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 878
tatiana_c Avatar asked Jan 04 '12 22:01

tatiana_c


People also ask

What is SensorEvent?

android.hardware.SensorEvent. This class represents a Sensor event and holds information such as the sensor's type, the time-stamp, accuracy and of course the sensor's data . Definition of the coordinate system used by the SensorEvent API.

What is onSensorChanged?

onSensorChanged(SensorEvent event) : Called when sensor values have changed.


1 Answers

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.

like image 68
Edward Falk Avatar answered Sep 28 '22 04:09

Edward Falk