WHAT DO I WANT TO DO? - Basically, I want to pragmatically make human contact at certain times with certain X, Y coordinates - Run a service that receives X, Y coordinates through some interface (TCP / UDP) - fire dispatchTouchEvent (), using these coordinates and getting the results, since an actual click of a personβs finger gives - I mean, the focal activity can be anything, either this is the Android Home screen or any open activity OR Anything - The moment service calls the dispatchTouchEvent () method, which should execute the click. - For example, if the open application is a calculator and the X, Y coordinates of dispatchTouchEvent () indicate a numeric value of 5, it should press the 5 key
WHAT DO I DO NOW? - I started a service that gets the X, Y coordinates - On some trigger, it calls dispatchTouchEvent (), but it does not work. He does not click on the screen. - It captures every touch event made by a human finger.
WHAT'S HAPPENING? - How to throw dispatchTouchEvent () for any pad action
SAMPLE CODE: Here I use the sample code. I just made it easy to test. First we need to click anywhere on the screen. Its X, Y coordinates will be saved and after a while dispatchTouchEvent () will be called using the same coordinates.
MainActivity.java
package com.test.overlay; import android.os.Bundle; import android.app.Activity; import android.content.Intent; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
Overlay.java
package com.test.overlay; import android.annotation.SuppressLint; import android.app.Service; import android.content.Context; import android.content.Intent; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.Typeface; import android.os.AsyncTask; import android.os.Build; import android.os.IBinder; import android.os.SystemClock; import android.view.Gravity; import android.view.MotionEvent; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.Toast; @SuppressWarnings("deprecation") public class Overlay extends Service { HUDView mView; @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); Toast.makeText(getBaseContext(),"onCreate", Toast.LENGTH_LONG).show(); mView = new HUDView(this); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT); params.gravity = Gravity.RIGHT | Gravity.TOP; params.setTitle("Load Average"); WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(mView, params); } @Override public void onDestroy() { super.onDestroy(); Toast.makeText(getBaseContext(),"onDestroy", Toast.LENGTH_LONG).show(); if(mView != null) { ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mView); mView = null; } } } class HUDView extends ViewGroup { private Paint mLoadPaint; public HUDView(Context context) { super(context); Toast.makeText(getContext(),"HUDView", Toast.LENGTH_LONG).show(); mLoadPaint = new Paint(); mLoadPaint.setAntiAlias(true);
Please point me in the right direction.