Issue
I'm working on Genymotion android emulator and I was looking at how to interact with it. I read that the events and Linux exposes a uniform input event interface for each device as /dev/input/eventX.
can that be done with an android emulator?? I mean is it possible for example to use java implementation to send mouse events to the emulator and inject to the /dev/input/eventX so that for example instead of touching we can use a button on the java application to interact with 2048 game and move up and down ??
hope it's a clear question :)
thanks :)
Solution
There are a lot of ways to interact with an Android emulator:
- You can reproduce gestures you applied "by hand" to your device, through ADB Shell you can use
getevent
andsendevent
commands. It can be a little bit laborious but you can read this very clear post to learn more. - You can also use
adb shell input
command where the "man output" is quite self-explanatory. It allows you to inject defined input like touchscreen, text input, etc. - You can also use UI Automator. It is quite useful to simulate user behavior from a Java project. You run from inside the phone.
- Then, you can also use MonkeyRunner, a Python API that allows you to script user-like behavior from outside the phone, through ADB. The better way if you want to script from outside your device.
- If you want to instrument gestures from inside your app you can use the Instrument class. It allows you to inject events and requires INJECT_EVENTS permission. Be careful, you cannot inject events outside your application if it is not a system app. To be a system app you need to sign your app with the system certificate, as explained here. As Genymotion and the Android SDK Emulator are using the AOSP default certificate, you will be able to get it easily.
Answered By - eyal-lezmy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.