1

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 :)

Omarkk
  • 83
  • 1
  • 11

1 Answers1

4

There are a lot of ways to interact with an Android emulator:

  1. You can reproduce gestures you applied "by hand" to your device, through ADB Shell you can use getevent and sendevent commands. It can be a little bit laborious but you can read this very clear post to learn more.
  2. 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.
  3. You can also use UI Automator. It is quite useful to simulate user behavior from a Java project. You run from inside the phone.
  4. 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.
  5. 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.
Community
  • 1
  • 1
eyal-lezmy
  • 7,090
  • 3
  • 41
  • 35
  • Hi eyal-lezmy Thanks for your reply, I used the monkeyRunner and it did the job for me. I have one more question, If I make a python scripts and I need to make a java of c# application that can run the script and the script will interact with the emulator. so for example, if i have an application that have one button say drag and inside the event handler there is a code that can run the script. do you think this is possible ?? as I know I can make a python code in VS and Eclipse but can they be for monkeyRunner ?? thanks for the help... – Omarkk Mar 16 '15 at 15:30
  • Basically, you can't do it in python because python runtime is not supported by Android OS. You will need to script in the native development language (Java & co). Another piont, whatever the solution you choose, is that you will need `system` or `root` user rights if you want to execute it to another app than your own. It means, don't think you can do it on consumer devices because it would be a security failure. 2 solutions: 1. Launch `get/sendevent` or `input` from your app requesting `su` just before. 2. Look at the 5th bullet point I added on the answer. – eyal-lezmy Mar 16 '15 at 22:19