J
J
JeremiSharkboy2017-05-23 11:25:15
Java
JeremiSharkboy, 2017-05-23 11:25:15

How to emulate a tap on the screen or a mouse click?

Essence of the question: you need to remotely press a button on the smartphone screen (for example, turn on some application or something else) by coordinates. How can I achieve this without adb shell?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PushnovN, 2017-06-07
@JeremiSharkboy

Good afternoon everyone.
As a result, the issue was resolved after installing root rights on Android and still through the commands in the terminal: input tap XY and input swipe X1 Y1 X2 Y2 .

public static Runtime rt;
public static Process process;
public static DataOutputStream os;

// Инициализируем переменные
rt = Runtime.getRuntime();
process = rt.exec("su");
os = new DataOutputStream(process.getOutputStream());

// Метод, исполняющий команды в терминале (можно выполнять в любом потоке).
// Примеры команд: 
//     input keyevent KEYCODE_VOLUME_DOWN
//     input tap 200 300
public static void execCommands(String... commands)
{
    try
    {
        for(int i = 0; i < commands.length; i++)
        {
            os.writeBytes(commands[i] + "\n");
            os.flush();
        }
    } catch (Exception e) { }
}

If suddenly someone knows how to do something like this without root , I will be very grateful. Interested in fresh versions of the OS (5.0+).

A
Alexey, 2017-05-23
@TheKnight

Depends on the degree of acceptable hemorrhoids. For example, you can look at Appium. Or delve into UIAutomator. This is so, offhand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question