T
T
TapochekF2018-02-26 18:57:02
Android
TapochekF, 2018-02-26 18:57:02

How to auto-click a button in an application?

There is an application where earlier it was necessary to prescribe values ​​and press the "next" button. But now the values ​​​​are automatically registered and pressing the "next" button has become superfluous. Can you tell me how to auto click on a button? Or at least what keywords to search for a solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Marken, 2018-02-27
@TapochekF

Hold) The method works on any view

private void emulationOnTouch(View v) {
        long downTime = SystemClock.uptimeMillis();
        long eventTime = SystemClock.uptimeMillis() + 100L;
        float x = 0.0F;
        float y = 0.0F;

        int metaState = 0;
        MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, 6661024, x, y, metaState);

        v.dispatchTouchEvent(motionEvent);
}

Call the method like this:
Button bin;
View v;

emulationOnTouch(btn);
emulationOnTouch(v);

D
Denis Zagaevsky, 2018-02-26
@zagayevskiy

The question is not clear. If you have the source codes of the application and you need to change it, you don’t need to do any auto-clicking, of course. You just need to execute the code that is executed on click. These are the basics, you will have to comprehend them somehow yourself, the question is from the section "how to add 2 and 2".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question