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?
我现在没有Android手机。但是在我的应用中,我需要使用加速度计的值。在一个模拟的环境中我怎么做呢?
5 个解决方案
#1
38
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:
Android模拟器本身不支持它,但OpenIntents的SensorSimulator填补了这个空白。下载并解压压缩文件,然后启动独立的jar文件:
$ java -jar bin/sensorsimulator.jar
Next, install SensorSimulatorSettings on the emulator using the adb tool which comes with the SDK:
接下来,使用adb工具在模拟器上安装SensorSimulatorSettings:
$ 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.
(运行adb设备查找仿真器设备名称)。最后,在模拟器中运行已安装的SensorSimulatorSettings应用程序,并输入IP地址10.0.2.2(不管SensorSimulator应用程序可能建议什么)。这是开发主机的环回设备的别名,所以应该始终有效。
#2
16
The recent version of emulator comes enabled with Accelerometer and other sensor simulation support. One can telnet localhost 5554
:
最新版本的仿真器支持加速计和其他传感器模拟。可以telnet localhost 5554:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
OK尝试127.0.0.1……连接到localhost。转义字符“^]”。Android控制台:为命令列表输入“help”
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
柯:失踪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
#3
6
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
上述步骤:“……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
接下来,使用SDK附带的adb工具在模拟器上安装SensorSimulatorSettings: $ adb -s install bin/SensorSimulatorSettings.apk
...Finally, run the installed SensorSimulatorSettings app in the emulator and enter the IP address 10.0.2.2..."
…最后,在模拟器中运行已安装的SensorSimulatorSettings app,输入IP地址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.
显然,您需要修改应用程序以使用传感器模拟器。您可以访问http://code.google.com/p/openintents/wiki/SensorSimulator,并向下滚动到“如何在应用程序中使用SensorSimulator”一节。
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.
即便如此,我在编译时还是有一些错误,所以您可能想看看这个页面:Android模拟器上的老式温度计组件+ SensorSimulator—我必须删除对Android .hardware的引用。传感器、SensorEvent 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.
然后它在连接模拟器的调用中失败了。显然,我需要给我的应用程序许可才能在manifest文件中使用Internet。
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.
在此之后,我可以使用传感器模拟器来虚拟地旋转我的手机,并且我可以在我的应用程序中获得相应的传感器读数。
#4
1
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.
我觉得目标10的模拟器不支持加速度计,但是目标15支持。我不知道是否有办法达到目标10。因此,要测试应用程序,请为目标15创建项目和AVD。
#5
0
I suggest you to use Genymotion application, it integrate a complete tool for the test of accelerometer and use a faster emulator: Genymotion
我建议您使用Genymotion应用,它集成了一个完整的加速度计测试工具,并使用一个更快的模拟器:Genymotion
#1
38
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:
Android模拟器本身不支持它,但OpenIntents的SensorSimulator填补了这个空白。下载并解压压缩文件,然后启动独立的jar文件:
$ java -jar bin/sensorsimulator.jar
Next, install SensorSimulatorSettings on the emulator using the adb tool which comes with the SDK:
接下来,使用adb工具在模拟器上安装SensorSimulatorSettings:
$ 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.
(运行adb设备查找仿真器设备名称)。最后,在模拟器中运行已安装的SensorSimulatorSettings应用程序,并输入IP地址10.0.2.2(不管SensorSimulator应用程序可能建议什么)。这是开发主机的环回设备的别名,所以应该始终有效。
#2
16
The recent version of emulator comes enabled with Accelerometer and other sensor simulation support. One can telnet localhost 5554
:
最新版本的仿真器支持加速计和其他传感器模拟。可以telnet localhost 5554:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
OK尝试127.0.0.1……连接到localhost。转义字符“^]”。Android控制台:为命令列表输入“help”
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
柯:失踪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
#3
6
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
上述步骤:“……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
接下来,使用SDK附带的adb工具在模拟器上安装SensorSimulatorSettings: $ adb -s install bin/SensorSimulatorSettings.apk
...Finally, run the installed SensorSimulatorSettings app in the emulator and enter the IP address 10.0.2.2..."
…最后,在模拟器中运行已安装的SensorSimulatorSettings app,输入IP地址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.
显然,您需要修改应用程序以使用传感器模拟器。您可以访问http://code.google.com/p/openintents/wiki/SensorSimulator,并向下滚动到“如何在应用程序中使用SensorSimulator”一节。
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.
即便如此,我在编译时还是有一些错误,所以您可能想看看这个页面:Android模拟器上的老式温度计组件+ SensorSimulator—我必须删除对Android .hardware的引用。传感器、SensorEvent 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.
然后它在连接模拟器的调用中失败了。显然,我需要给我的应用程序许可才能在manifest文件中使用Internet。
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.
在此之后,我可以使用传感器模拟器来虚拟地旋转我的手机,并且我可以在我的应用程序中获得相应的传感器读数。
#4
1
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.
我觉得目标10的模拟器不支持加速度计,但是目标15支持。我不知道是否有办法达到目标10。因此,要测试应用程序,请为目标15创建项目和AVD。
#5
0
I suggest you to use Genymotion application, it integrate a complete tool for the test of accelerometer and use a faster emulator: Genymotion
我建议您使用Genymotion应用,它集成了一个完整的加速度计测试工具,并使用一个更快的模拟器:Genymotion