title: How to execute a tap with given coordinates in Android
body: <p>I need to have an automatic tap executed onscreen with given coordinates without any user input.</p>
  
  <p>So when i call this function with given coordinates that i already found out via developer tools, then it should simulate the user clicking the screen right there.</p>
  
  <p>this is the code:</p>
  
  <pre><code>public void simulateClick(float x, float y) {
          long downTime = SystemClock.uptimeMillis();
          long eventTime = SystemClock.uptimeMillis();
          MotionEvent.PointerProperties[] properties = new MotionEvent.PointerProperties[1];
          MotionEvent.PointerProperties pp1 = new MotionEvent.PointerProperties();
          pp1.id = 0;
          pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
          properties[0] = pp1;
          MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1];
          MotionEvent.PointerCoords pc1 = new MotionEvent.PointerCoords();
          pc1.x = x;
          pc1.y = y;
          pc1.pressure = 1;
          pc1.size = 1;
          pointerCoords[0] = pc1;
          MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime,
                  MotionEvent.ACTION_DOWN, 1, properties,
                  pointerCoords, 0,  0, 1, 1, 0, 0, 0, 0 );
          dispatchTouchEvent(motionEvent);
  
          motionEvent = MotionEvent.obtain(downTime, eventTime,
                  MotionEvent.ACTION_UP, 1, properties,
                  pointerCoords, 0,  0, 1, 1, 0, 0, 0, 0 );
          dispatchTouchEvent(motionEvent);
      }
  </code></pre>
  
  <p>Yet it doesnt work or do anything, its not giving me errors, its just not doing anything...</p>