如何模拟android传感器事件?

时间:2022-02-11 00:16:41

It's possible to simulate, for instance, events for android accelerometer?

例如,可以模拟android加速度计的事件吗?

Imagine the following scenario: I have an app that at some point, if detect a X value from accelerometer, show a dialog with a question to the UI.

想象一下以下场景:我有一个应用程序,在某些时候,如果从加速度计检测到X值,则向UI显示一个带有问题的对话框。

I want to make a test for it. To do so, I want to simulate a shake with that X value programatically, and check if the dialog appears.

我想为它做一个测试。为此,我想以编程方式模拟具有该X值的抖动,并检查对话框是否出现。

I already know Sensor Simulator, but there is a way to send a value for accelerometer or other sensor and receive that changes with SensorEventListener?

我已经知道传感器模拟器,但是有一种方法可以为加速度计或其他传感器发送值并使用SensorEventListener接收更改吗?

Thanks in advance,

提前致谢,

1 个解决方案

#1


0  

It's impossible. Because sensor event is triggered by hardware, android system get the data from hardware and don't provide interface to change the data or to trigger an sensor event. So we can't simulate a sensor event programatically. Using Sensor Simulator, or you can change the source code of android framework.

不可能。因为传感器事件是由硬件触发的,所以android系统从硬件获取数据并且不提供用于更改数据或触发传感器事件的接口。因此我们无法以编程方式模拟传感器事件。使用Sensor Simulator,或者您可以更改android框架的源代码。

#1


0  

It's impossible. Because sensor event is triggered by hardware, android system get the data from hardware and don't provide interface to change the data or to trigger an sensor event. So we can't simulate a sensor event programatically. Using Sensor Simulator, or you can change the source code of android framework.

不可能。因为传感器事件是由硬件触发的,所以android系统从硬件获取数据并且不提供用于更改数据或触发传感器事件的接口。因此我们无法以编程方式模拟传感器事件。使用Sensor Simulator,或者您可以更改android框架的源代码。