GestureDetector at TYPE_SYSTEM_OVERLAY

I created TYPE_SYSTEM_OVERLAY and I want to record finger / touch events on this overlay using service .

Overlay works fine, but the problem is that it cannot record touch events when I try to include a GestureDetector in it. When I click on the screen, the toast msg "onDown" did not show.

would be grateful if someone would tell me where I was wrong :( I tried to implement the GestureDetector outside the OverlayView class, but also no result.

 public class NUSLogService extends IntentService { OverlayView mView; @Override public void onCreate() { super.onCreate(); final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT); params.gravity = Gravity.RIGHT | Gravity.BOTTOM; params.setTitle("TouchLayer"); mView = new OverlayView(getApplicationContext()); final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(mView, params); } @Override public void onDestroy() { super.onDestroy(); if(mView != null) { ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mView ); mView = null; } } //self-created overlay class class OverlayView extends ViewGroup implements OnGestureListener{ private GestureDetector gestureScanner = new GestureDetector(this); public OverlayView(Context context) { super(context); Toast.makeText(getContext(),"OverlayView", Toast.LENGTH_SHORT).show(); } @Override public boolean onTouchEvent(MotionEvent event) { // return super.onTouchEvent(event); return gestureScanner.onTouchEvent(event); } @Override protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) { // TODO Auto-generated method stub } @Override public boolean onDown(MotionEvent e) { Toast.makeText(getContext(),"onDown", Toast.LENGTH_SHORT).show(); return false; } } 
+2
java android service gesturedetector overlay
source share
1 answer

First, it should not be an IntentService . In your current implementation, onDestroy() will be called a millisecond or two after onCreate() .

Secondly, TYPE_SYSTEM_OVERLAY cannot receive any touch events with Android 4.0 for security reasons.

+2
source share

All Articles