简体   繁体   English

通过服务覆盖视图传递触摸事件

[英]Pass touch events through service overlay view

I have a Service which displays some info and a button over the system screens. 我有一个服务,该服务在系统屏幕上显示一些信息和一个按钮。 I want touch events to pass through the Service view and act normally on the apps/screens below it. 我希望触摸事件通过“服务”视图并在其下方的应用程序/屏幕上正常运行。 This is my code 这是我的代码

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:background="@color/colorPrimary"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="false"
    >


    <RelativeLayout
        android:clickable="false"
        android:background="@color/colorPrimary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TEXT GOES HERE"
            android:layout_below="@+id/button"
            android:layout_margin="30dp"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:id="@+id/button"
            android:text="button"/>
    </RelativeLayout>

</RelativeLayout>

Service Code: 服务代码:

    final WindowManager.LayoutParams params;

            params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
params.gravity = Gravity.BOTTOM | Gravity.LEFT;


        mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mWindowManager.addView(myView, params);

I want touch events to pass through the Service view and act normally on the apps/screens below it 我希望触摸事件通过“服务”视图并在其下方的应用程序/屏幕上正常运行

Fortunately, this is no longer possible. 幸运的是,这不再可能。 What you are describing is a tapjacking attack, where an app spies on user input while still allowing that input to proceed normall. 您所描述的是一种tap窃攻击,其中一个应用在监视用户输入的同时仍允许该输入正常进行。 This has been blocked for several years, for privacy and security reasons. 由于隐私和安全原因,此方法已被阻止了好几年。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM