How to simulate touch from background service with sendevent or other way?

android simulate touch without root
android accessibility service touch event
android simulate click on screen
android simulate touch on view
android trigger ontouch
tasker shell input tap
android simulate touch with mouse
adb shell input tap

Is it possible to simulate touch from the background application (or service) or to run sh script (that simulate touch)?

It is needed for testing android system without USB or other connection to PC, thats why I can't (or don' know how) use Monkey or other autotest tools.

Added info: I found the way to run shell commands with root (tested devices rooted):

Unable to execute sendevent shell command through the android code (create touch simulation). Writing file on system partition (run commands with root permissions)

Also I get events to simulate touch.

As a result I have:

//sendevent commands to simulate touch (verify it work from cmd)
String[] touchEvent = { "sendevent /dev/input/event0 0 0 0\n",
                        "sendevent /dev/input/event6 3 53 499\n",
                        "sendevent /dev/input/event6 3 54 680\n",
                        "sendevent /dev/input/event6 3 58 40\n",
                        "sendevent /dev/input/event6 3 48 3\n",
                        "sendevent /dev/input/event6 3 57 0\n",
                        "sendevent /dev/input/event6 0 2 0\n",
                        "sendevent /dev/input/event6 0 0 0\n",
                        "sendevent /dev/input/event6 0 2 0\n",
                        "sendevent /dev/input/event6 0 0 0\n",
                        "sendevent /dev/input/event0 3 0 2\n",
                        "sendevent /dev/input/event0 0 0 0\n"};

try{
    Thread.sleep(2000);
    Process root = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(root.getOutputStream());             
    for(int i = 0; i < touchEvent.length; i++){
            Log.i(TAG, touchEvent[i]);  
            os.writeBytes(touchEvent[i]);
            os.flush();
    }
    root.waitFor();
} catch (IOException e) {
    Log.e(TAG, "Runtime problems\n");
    e.printStackTrace();
} catch (SecurityException se){
    se.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
}

I have no any exceptions, but it is not touch simulates.

Can anybody help to solve this problem?

If there is another way to do it with android ndk or daemon on C, please tell me about it.

Thanks.

Programmatically Injecting Events on Android – Part 2 – PocketMagic, How to simulate touch from background service with sendevent or other way? Is it possible to simulate touch from the background application (or service) or to run� 33 How to simulate touch from background service with sendevent or other way? Feb 18 '13 32 How to simulate touch from background service with sendevent or other way?

I was about to implement your solution when I found an easier one - posting in the hope it will be helpful to someone. Since you already have a rooted device, you don't need to sign as a system app.

To simulate a touch at position (100,200), all you need to is call input from within the service using Runtime.exec as follows:

Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
String cmd = "/system/bin/input tap 100 200\n";
os.writeBytes(cmd);
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();

异常中心网(ExceptionCenter)|Android|How to simulate touch from , Where I am stuck now is that I can't figure out what the right action is to simulate an actual tap through instrumentation – i.e. pressing a button. I've� But I need it completed in one single touch, so I'm trying to use sendevent for the first time. I thought this would get me there, but I'm not doing something right: sendevent /dev/input/event1 3 57 0 sendevent /dev/input/event1 3 53 1350 sendevent /dev/input/event1 3 54 1350 sendevent /dev/input/event1 0 2 0 sendevent /dev/input/event1 0 0 0

You can use the "swipe" input. Looking at the Input.java source code you can see the needed parameters to make a swipe.

Here is a gist I made for simulating a swipe for playing the smove game with clicks instead of swipes just to test this. You need super user access to use this implementation though.

Is it possible to simulate touch without root?, 异常中心网(ExceptionCenter)|Android|How to simulate touch from background service with sendevent or other way?|Is it possible to simulate touch from the� Notice that the <service> element doesn't contain an intent filter. The Activity that sends work requests to the service uses an explicit Intent, so no filter is needed. This also means that only components in the same app or other applications with the same user ID can access the service.

Input events overview, You can potentially simulate a touch with the command input tap x y (e.g. from a terminal emulator, or possibly with Tasker (can't remember if it� Is there any way to simulate a touch (anywhere) on the screen without root? If not, is there any other way I can perform a cardboard 'select' action without magnet support, or opening up my cardboard every time? Background. I am trying to get cardboard apps to work to work with a 5.1 phone which doesn't support the magnet 'button'.

Track touch and pointer movements, Event listeners; Event handlers; Touch mode; Handling focus. On Android, there's more than one way to intercept the events from a user's� Track velocity. You could have a movement-based gesture that is simply based on the distance and/or direction the pointer traveled. But velocity often is a determining factor in tracking a gesture's characteristics or even deciding whether the gesture occurred.

Understand Alexa Presentation Language (APL), There are several different ways to track movement in a gesture, depending on the needs of your application. For example: The starting and� I'm trying to simulate a touch on my iPhone without actually touching it (with a finger) for an app I'm making, I already tried electricity and it didn't worked, what is the correct way of doing it? edit: I'm trying to simulate a touch physically, I need to understand the touch screen mechanism to find some sort of material.

Comments
  • if your on the same local network you can use monkey, adb will work over wireless as well.
  • Thanks for the reply. I know about it, but there should not any connection (WiFi and BT should be off).
  • Hi, how do you eventually accomplish this? I followed all your steps but no good news, please review my question I had posted here
  • Great, thanks. Can you please tell me what was the Android version on which you tested the code? Instrumentation works well on versions before Lollipop. I think Lollipop needs some extra work to have the instrumentation running, have you faced this problem? Or, do you know any possible solution?
  • I developed it on March 2013, there was no lollipop version, or it was only on preview version, I don't remember right. So I tested it only on Jelly Bean.
  • v1kI this is the first time I try to get files of the system. I can't figure out how to get the files to make the app as system app. Can you please help me? Can you tell me the steps to do that?
  • First of all, you should have an access to android OS sources, if you try to develop system app, you obviously have system, that would contain your app. There is root folder with a sources, for compiling android, so it's equals "root-of-android-source-tree" in my answer.
  • v1k thanks I've read your answer. My question is how to access "root-of-android-source-tree". Is it something on the device, pc, or something I get by installing another component? How can I access the root folder?
  • That's a much cleaner solutionl. Unfortunately it doesn't have event like touch_down, touch_up or move_to, which is much needed by me. :(
  • Thanks , it worked on my galaxy s4 5.0.1 default ROM but it works rarely on some devices like galaxy s6 6.0.1 rooted.It's so wearied! Why?
  • Looks like you don't even need the device rooted. A plain Runtime.getRuntime().exec("/system/bin/input tap 100 400"); did the trick for me on a standard non-rooted Android 7.0 device.