如何在 Android 模拟器中模拟加速度计?

发布于 2024-10-15 08:36:25 字数 1539 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

无法言说的痛 2024-10-22 08:36:25

Android 模拟器本身不支持它,但 OpenIntents 的 SensorSimulator 填补了这一空白。下载并解压 zip 文件,然后启动独立的 jar 文件:

nbsp;java -jar bin/sensorsimulator.jar

接下来,使用 SDK 附带的 adb 工具在模拟器上安装 SensorSimulatorSettings:(

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

运行 adb devices 以查找模拟器设备名称)。最后,在模拟器中运行已安装的 SensorSimulatorSettings 应用程序并输入 IP 地址 10.0.2.2(不管 SensorSimulator 应用程序可能会建议什么)。这是开发主机的环回设备的别名,因此应始终为有效的。

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.

热风软妹 2024-10-22 08:36:25

最新版本的模拟器启用了加速度计和其他传感器模拟支持。可以telnet localhost 5554

尝试 127.0.0.1...
已连接到本地主机。
转义字符为“^]”。
Android 控制台:输入“help”获取命令列表
好的

传感器
允许您请求模拟器传感器

可用的子命令:
状态列出所有传感器及其状态。
获取传感器值
设置传感器值

KO:缺少子命令

传感器状态
加速:已启用。
磁场:启用。
方向:启用。
温度:启用。
邻近度:已启用。
好的

,我不知道到底如何模拟震动。尝试快速地一个接一个地发送这两个命令:

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

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
咽泪装欢 2024-10-22 08:36:25

我也试图让 SensorSimulator 工作,我想我终于让它工作了。

上述步骤:
"...java -jar bin/sensorsimulator.jar

接下来,使用 SDK 附带的 adb 工具在模拟器上安装 SensorSimulatorSettings:
$ adb -s install bin/SensorSimulatorSettings.apk

...最后,在模拟器中运行已安装的 SensorSimulatorSettings 应用程序并输入 IP 地址 10.0.2.2...”

是一个好的开始,但我需要做更多。

您显然需要然后修改您的应用程序以使用 SensorSimulator。您可以访问 http://code。 google.com/p/openintents/wiki/SensorSimulator 并向下滚动到“如何在应用程序中使用 SensorSimulator”部分。

即便如此,我在编译时也遇到了一些错误,因此您可能想查看此页面: Android 模拟器上的老式温度计组件 + SensorSimulator< /a> - 我必须删除对 android.hardware.Sensor、SensorEvent 和 SensorEventListener 的引用,

然后在调用 connectSimulator 时失败。显然,我需要在清单文件中授予我的应用程序使用互联网的权限。 。

毕竟,我可以使用 SensorSimulator 虚拟旋转我的手机,并且我确实在应用程序中获得了相应的传感器读数。

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.

旧时模样 2024-10-22 08:36:25

我发现目标 10 的模拟器不支持加速度计,但目标 15 的模拟器支持。不知道有没有办法实现目标10。
因此,为了测试您的应用程序,请为目标 15 创建项目和 AVD。

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.

半世蒼涼 2024-10-22 08:36:25

我建议您使用 Genymotion 应用程序,它集成了用于测试加速度计的完整工具并使用更快的模拟器:Genymotion

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文