Android : Touching a view that's always on screen

on Tuesday, September 16, 2014


I have a view that's always on the screen (over other apps), I wan't to receive touch events and than to pass them farther.


The code from the running Service :



WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);

v.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(getApplicationContext(), "view touched", Toast.LENGTH_SHORT).show();
return false;
}
});

WindowManager localWindowManager = (WindowManager)getSystemService("window");
localWindowManager.addView(v, localLayoutParams);


currently I don't get the touches.


0 comments:

Post a Comment