Android 是否可以创建服务覆盖并拦截所有触摸事件数据?
Android is it possible to create a service overlay and intercept all touch event data?
你好,我正在尝试创建一个透明覆盖层来拦截(并且不会阻止其他应用程序)我在智能手机上执行的所有触摸事件,特别是我对滚动事件感兴趣,这是来自的代码我的服务 class:
@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 类型的运动事件,我需要所有的事件数组来跟踪滚动,提前谢谢你!
I am trying to create a transparent overlay that intercepts ( and does not block the other applications) all the touch events I do on my smartphone
幸运的是,出于明显的隐私和安全原因,这在 Android 4.0+ 上是不可能的。恶意软件作者喜欢这种 "tapjacking" 攻击,无形中监视用户输入。
你好,我正在尝试创建一个透明覆盖层来拦截(并且不会阻止其他应用程序)我在智能手机上执行的所有触摸事件,特别是我对滚动事件感兴趣,这是来自的代码我的服务 class:
@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 类型的运动事件,我需要所有的事件数组来跟踪滚动,提前谢谢你!
I am trying to create a transparent overlay that intercepts ( and does not block the other applications) all the touch events I do on my smartphone
幸运的是,出于明显的隐私和安全原因,这在 Android 4.0+ 上是不可能的。恶意软件作者喜欢这种 "tapjacking" 攻击,无形中监视用户输入。