0

I want to automatically create a consent button when the permission window is displayed on Android

I clicked on the root view, but clicked the main view instead of the permission window Click on the permission window

private void autoClick(float x, float y) {

    try {
        Thread.sleep(2000);
    }
    catch (Exception e)
    {
    }

    // Obtain MotionEvent object
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();

    int metaState = 0;
    MotionEvent keyDown = MotionEvent.obtain(
            downTime,
            eventTime,
            MotionEvent.ACTION_DOWN,
            x,
            y,
            metaState
    );

    MotionEvent keyUp = MotionEvent.obtain(
            downTime,
            eventTime,
            MotionEvent.ACTION_UP,
            x,
            y,
            metaState
    );

    //keyDown.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    //keyUp.setSource(InputDevice.SOURCE_TOUCHSCREEN);

    getWindow().getDecorView().getRootView().dispatchTouchEvent(keyDown);
    getWindow().getDecorView().getRootView().dispatchTouchEvent(keyUp);

    //findViewById(android.R.id.content).getRootView().dispatchTouchEvent(keyDown);
    //findViewById(android.R.id.content).getRootView().dispatchTouchEvent(keyUp);
}
eunoia
  • 3
  • 2
  • Is this for a test, or intended to automatically grant yourself the permission in the app itself? – Ryan M Jun 25 '20 at 03:26
  • It's for testing, but it's also for getting permission. – eunoia Jun 25 '20 at 04:14
  • So, you definitely can't do this outside of a test, because if you _could_, that would defeat the entire point of a permission prompt. – Ryan M Jun 25 '20 at 04:32
  • Thank you for answer I want to click on a specific location like an auto clicker Is it impossible? – eunoia Jun 25 '20 at 04:35
  • Does this answer your question? [How to grant permissions to android instrumented tests?](https://stackoverflow.com/questions/50403128/how-to-grant-permissions-to-android-instrumented-tests) – Ryan M Jun 25 '20 at 04:43
  • Does this answer your question? [How can I reliably simulate touch events on Android without root (like Automate and Tasker)?](https://stackoverflow.com/questions/50775698/how-can-i-reliably-simulate-touch-events-on-android-without-root-like-automate) – Ryan M Sep 03 '21 at 03:50

0 Answers0