避免为使用SYSTEM_ALERT_WINDOW的服务检测到屏幕覆盖 [英] Avoid Screen Overlay Detected for service that uses SYSTEM_ALERT_WINDOW

查看:210
本文介绍了避免为使用SYSTEM_ALERT_WINDOW的服务检测到屏幕覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用主要用途是叠加层,该叠加层是通过服务运行的.

My app main usage is overlay, the overlay is running from a service.

Android安全性添加漂亮的

Android Security add the nice "Screen Overlay Detected"

当用户尝试更改权限时,我想避免检测到屏幕覆盖".所以...我添加了一个AccessiblityService来检测:

I want to avoid "Screen Overlay Detected" when user tries to change permissions. so... I've add an AccessiblityService that detects:

if ( event.getPackageName().equals("com.google.android.packageinstaller") ){
    stopService(myServiceIntent);
}

但是,即使现在我仍然看到此消息. (当我的服务停止时...).

However, even now I see this message popping. (when my service is stopped...).

我看到暮光之城做到了毫无问题

我想念什么?

p.s. -我也尝试过构建签名的apk,但看到的行为完全相同.

p.s. - I've also tried building a signed apk but saw exact same behavior.

推荐答案

看来我已经能够解决这个问题.

It seems I've been able to resolve this.

a)不能确定stopService将停止您的服务. 如此处所述:

a) stopService isn't assured your service will be stopped. as described here :

直到所有这些绑定被删除,它才会被销毁.有关服务生命周期的更多详细信息,请参见>服务文档.

It will not be destroyed until all of these bindings are removed. See > the Service documentation for more details on a service's lifecycle.

b)我能够通过发送名为stopSelf()的意图来终止我的服务. 但是,进程终止/启动可能很慢.

b) I was able to kill my service by sending intent that called stopSelf(). However process killing/starting can be slow.

c)最佳分辨率:因此Android似乎会检查视图的可见性.无需终止服务或进行任何更复杂的操作.

c) Best resolution: so it seems Android checks for view visibility. no need to kill services or do anything more complicated.

我目前的操作方式: -AccessibilityService(已由我的应用程序使用)监视"com.google.android.packageinstaller",但可以将其细化为以下类:"com.android.packageinstaller.permission.ui.ManagePermissionsActivity"

Current way I'm doing it: - AccessibilityService (already used by my app) monitor "com.google.android.packageinstaller" though it can be refined to class: "com.android.packageinstaller.permission.ui.ManagePermissionsActivity"

  • 一旦在此类中检测到,我们便将Intent发送给鸭子",当我们外出时,我们将发送另一个我们要继续使用的intent.

  • Once detected in this class, we send Intent to "duck", and when we're out, we send another intent that we're back on.

该服务通过以下方式处理这些呼叫:

The service handles those calls by:

[ourView].setVisibility(View.INVISIBLE); // when permission settings shown

[ourView].setVisibility(View.VISIBLE); // when normal flow

这篇关于避免为使用SYSTEM_ALERT_WINDOW的服务检测到屏幕覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆