您好我正在尝试创建一个透明的覆盖层来拦截(并且不阻止其他应用程序)我在智能手机上执行的所有触摸事件,特别是我对滚动事件感兴趣,这是我的服务类中的代码:
@Override
public void onCreate() {
super.onCreate();
windowManager=(WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
view=new LinearLayoutCompat(this);
LayoutParams params=new LayoutParams(1, ViewGroup.LayoutParams.MATCH_PARENT);
view.setLayoutParams(params);
view.setOnTouchListener(this);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LayoutParams params = new LayoutParams(
1, /* width */
1, /* height */
LayoutParams.TYPE_PHONE,
LayoutParams.FLAG_NOT_FOCUSABLE
| LayoutParams.FLAG_NOT_TOUCH_MODAL
| LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSPARENT
);
params.gravity = Gravity.LEFT | Gravity.TOP;
windowManager.addView(view, params);
return super.onStartCommand(intent, flags, startId);
}
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Log.d(TAG,motionEvent.toString());
return false;
}
但是,有了这个我只能得到 ACTION_OUTSIDE 类型的运动事件,我需要所有的事件数组来跟踪滚动,提前谢谢你!