I\'m just wondering to know if a can with a background service have co-ordinates of a touch screen event in all activities.
Such like that
*final TextVie
I'm just wondering to know if a can with a background service have co-ordinates of a touch screen event in all activities.
No, sorry. Your activities can pass information about touch events to a service, but a service cannot directly receive touch events.
possible similar ideas to this problem:
have all activities have the same logic that will send the touch events . you can have a base activity that will have this logic , which all of your activities extend.
have an on top view which will collect the touch events , using a system alert permission . don't forget to close the activity that holds it when needed , though , since it will keep catching touch events even after the app is hidden.
here's a sample code to set a view on top:
final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
final View view=findViewById(R.id.view1);
final ViewGroup parent=(ViewGroup)view.getParent();
parent.removeView(view);
param.format=PixelFormat.RGBA_8888;
param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity=Gravity.TOP|Gravity.LEFT;
param.width=view.getLayoutParams().width;
param.height=view.getLayoutParams().height;
final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(view,param);
// TODO handle overlapping title bar and/or action bar
// TODO you must add logic to remove the view
// TODO you must use a special permission to use this method :android.permission.SYSTEM_ALERT_WINDOW