It's possible to simulate, for instance, events for android accelerometer?
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.
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.
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?
Thanks in advance,
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.
Related
is there a sensor in android to detect a tap on the device? I have a service and I want to detect when the user touches the phone. He can touch(tap) the screen, back or any other part of the device and it will trigger a function within my service. Is that possible? For example, if I have the device in my pocket, and I want my service to call a certain function when the user tap the phone from outside his pocket. Thanks.
You can use the accelerometer. The accelerometer detects a force on the device, and a tap would cause a force. The trick would be filtering out other forces, such as bouncing when walking.
My Android app wants to track the external mouse movement(either Bluetooth mouse or USB mouse).
I wrote a customized View to monitor the mouse events, but the events stop producing when mouse moves to the edge of the screen. I can understand that in most cases, there is no need to track the movement which occurs outside of the device screen. But I do need to monitor that kind of mouse movement.
I guess it can be monitored by the low level API. But can anyone point me to the right direction? Thanks.
well... how about that you got the key event when user input the bank password......
You may not get the key event if your activity or service not active but you may hijack the event from low level.
You can first change the /dev/input/eventX r/w value since all the event comes here, i.e. all the input event.
then you need write an C program e.g. to a dynamic library to select or epoll the event.
finally you can implement a JNI API to get the event from your apps.
Here we are.
I am making a screen lock app. In this app when user listen call then screen turn off and screen lock activate due to proximity sensor.
I have done many tries with different angles but failed.
Now I want to disable proximity sensor with the help of code in my app.
I am developing an App where I can receive call when mobile is brought near to ear, I have done that, now problem is call is received even when something come close to sensor inside my pocket. How can I resolve this issue?
To resolve this issue, you have to check at what angle the device is rotated in x,y,z direction before taking a call,(generally in a 'L' shape from pocket to ear) like the angle movements made when the device is lifted up to the ear.Then you will be able to distinguish between a call and device in pocket.
I read this unable to detect shake event when my phones screen is off in android article. But this question is differ from this.
I created an application which speak (using TextToSpeach API) time when I shake device. For that I have created a "Service" in which "ShakeListener" was registered. While I shake device, it will speak current time.
But this works fine while my device is "ON". When I lock my device, it stops working. Can any one elaborate what is the problem behind?
I think the problem here is that when you lock the device, it goes to sleep mode. And your ShakeListener doesn't receive shake events. The best way to implement what you want would be to register broadcast receiver to receive shake events. But as I know, android doesn't provide such broadcast. Another solution is to acuire a partial WakeLock. It'll prevent android from sleep. But of course it'll cause battery issues. Also take a look on this thread: Android accelerometer not working when screen is turned off
Probably you can not receive this notification until you patch some kernel implementation. Android doesn't broadcast such notification.