Omarkk
Omarkk

Reputation: 83

interacting with android emulator

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

Upvotes: 1

Views: 4338

Answers (1)

eyal-lezmy
eyal-lezmy

Reputation: 7116

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.

Upvotes: 4

Related Questions