android - 通过服务覆盖视图传递触摸事件
问题描述
我有一个服务,它在系统屏幕上显示一些信息和一个按钮。我希望触摸事件通过服务视图并在其下方的应用程序/屏幕上正常运行。这是我的代码
<?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>
服务代码:
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);
解决方案
我希望触摸事件通过服务视图并在其下方的应用程序/屏幕上正常运行
幸运的是,这不再可能。您所描述的是一种窃听攻击,其中应用程序监视用户输入,同时仍允许该输入正常进行。出于隐私和安全原因,这已被阻止数年。
推荐阅读
- reactjs - 如何使用 Enzyme 模拟背景单击 Material-ui 的模态窗口?
- r - 使用 P-splines 拟合数据时,数据集是否需要分为验证集和测试集?
- stata - 在时间间隔内随机选取年份
- java - 使用 ldap 时出现 AcceptSecurityContext 错误
- swift - Vapor 服务器抛出的错误是字符串,而不是响应中的错误
- python - 当访问一个不可调用的属性运行一个方法时,它在 Python 中调用了什么,它是如何完成的?
- assembly - 超时内的串行字节检查 (asm)
- r - 如何编写函数或循环以用列名替换二进制值?
- html - 如何在Vuetify的布局中居中元素?
- java - 使用两个线程顺序打印奇偶数