Page 1 of 4
When developing apps which use the sensors, the more realistic the environment for testiing the better. The earlier SensorArrow tutorial showed how to create an app which uses the OpenIntents simulator to let you send events via a wireframe handset representation. This is great, and extremely useful in many situations, but it has some drawbacks. To complement it we present the SensorPlayer, an app to record and sensor movements from your physical device and replay them either back there or on the emulator.
The saying goes that necessity is the mother of invention. I was writing a Android app which made heavy use of the Sensors and realised the emulator just wasn't real-world enough. The OI SensorSimulator is perfect for many situations but I encountered three drawbacks. First, because of the way it works via the mouse it isn't very accurate. Tilt left, tilt right, find bug. Tilt left, tilt right, bug doesn't appear - oops, didn't tilt enough the second time. The second problem is the readings aren't very real world. No matter how much you drag a mouse on the screen it can't give the same results as waving your physical handset about. And thirdly it isn't repeatable. For automated testing, you need to be able to inject exactly the same sensor readings to your app each time.
SensorPlayer is what became of my work to physically record sensor movements and save them as an XML file on the sdcard. Then in the emulator, copy that file to its virtual sdcard and run the app which uses them, so replaying in software exactly what we had recorded on the device.
These screenshots show a really basic app - it moves a banana around the screen in response to handset tilts(!) - but uses the SensorPlayer. In its current configuration it just records the orientation events, but later I explain how to extend it to other sensors. A hook must be added to the app to bring up the SensorPlayers menu, in this case a screen tap. The "Start recording" option is chosen and you can see the notification bar shows when recording is active. The handset is tilted and another screen tap lets you stop the recording and name it. Then in the main menu, "Start playback" lets you choose the sequence and play it back, again the notification area shows when this is happening. In this example the banana faithfully follows your initial sequence each time.