开发者

How can i simulate accelerometer in android emulator? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for book开发者_开发技巧s, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 6 years ago.

Improve this question

I don't have an Android phone right now. But in my application I need to use the accelerometer values. How can I do this in a simulated environment?


The Android emulator doesn't support it itself but OpenIntents' SensorSimulator fills the void. Download and unpack the zip file, then start the standalone jar file:

$ java -jar bin/sensorsimulator.jar

Next, install SensorSimulatorSettings on the emulator using the adb tool which comes with the SDK:

$ adb -s <emulator device> install bin/SensorSimulatorSettings.apk

(run adb devices to find the emulator device name). Finally, run the installed SensorSimulatorSettings app in the emulator and enter the IP address 10.0.2.2 (despite what the SensorSimulator application might suggest. This is an alias to the loopback device of the development host so should always be valid.


The recent version of emulator comes enabled with Accelerometer and other sensor simulation support. One can telnet localhost 5554:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
OK

sensor
allows you to request the emulator sensors

available sub-commands:
status list all sensors and their status.
get get sensor values
set set sensor values

KO: missing sub-command

sensor status
acceleration: enabled.
magnetic-field: enabled.
orientation: enabled.
temperature: enabled.
proximity: enabled.
OK

How exactly to simulate a shake, I don't know. Try sending these two commands one after the other rapidly:

sensor set acceleration 0:0:0
sensor set acceleration 99:99:99


I also was trying to get the SensorSimulator working and I think I finally got it working.

The above steps: "...java -jar bin/sensorsimulator.jar

Next, install SensorSimulatorSettings on the emulator using the adb tool which comes with the SDK: $ adb -s install bin/SensorSimulatorSettings.apk

...Finally, run the installed SensorSimulatorSettings app in the emulator and enter the IP address 10.0.2.2..."

are a good start, but I needed to do more.

You apparently need to then modify your application to use the SensorSimulator. You can go to http://code.google.com/p/openintents/wiki/SensorSimulator and scroll down to the "How to use the SensorSimulator in your application" section.

Even then I got some errors in compiling, so you might want to see this page: Vintage Thermometer component + SensorSimulator on the Android emulator - I had to remove the references to android.hardware.Sensor, SensorEvent, and SensorEventListener.

And then it was failing at the call to connectSimulator. Apparently, I needed to give my application permission to use the Internet in the manifest file.

After all that, I am able to use the SensorSimulator to virtually rotate my phone and I do get the corresponding sensor readings in my application.


I experienced that emulator for target 10 doesn't support accelerometer but for target 15 it does. I dont know if there is a way to do it for target 10. So for testing your application, Create your project and AVD for target 15.


I suggest you to use Genymotion application, it integrate a complete tool for the test of accelerometer and use a faster emulator: Genymotion

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜