简体   繁体   English

检测到屏幕叠加 - 如何在屏幕叠加应用中处理此问题

[英]Screen overlay detected - How to handle this in an screen overlay app

Some devices have extra security features and check if an app is drawing on top of others, when showing a permission dialog. 某些设备具有额外的安全功能,并在显示权限对话框时检查应用是否在其他设备上绘制。

I have a sidebar app, and my app has to be disabled, before users can accept a system dialog. 我有一个侧边栏应用程序,我的应用程序必须被禁用,然后用户才能接受系统对话框。

Questions 问题

  • How am I supposed to handle this case? 我怎么处理这个案子?
  • Is there a way to listen for an "System dialog shown" event, so that I can remove my sidebar and a "System dialog finished" so that I know, i can continue with my sidebar overlay? 有没有办法听一个“显示系统对话框”事件,这样我就可以删除我的侧边栏和“完成系统对话框”,以便我知道,我可以继续我的侧边栏覆盖? I know, that it's enough to stop the service (you don't have to remove the permission), so this would be a solution as well 我知道,这足以停止服务(你不必删除权限),所以这也是一个解决方案

EDIT 编辑

One solution I can think of is following: 我能想到的一个解决方案如下:

Using the AccessibilityService to check current foreground apps/views. 使用AccessibilityService检查当前的前台应用程序/视图。 There I will be able to check events that show me current foreground activities and even views... 在那里,我将能够检查显示当前前景活动甚至视图的事件......

My problems: 我的问题:

  • I don't know how to identify a permission dialog there. 我不知道如何识别那里的权限对话框。
  • Secondly, this forces me to ask the user to get this permission (which I want to avoid, but having a solution with this service, would already be an improvement for me, because some users give this permission to my app already - I would have to ask all then and explain the reason, which is something I can live with). 其次,这迫使我要求用户获得此权限(我想避免,但是使用此服务的解决方案,对我来说已经是一个改进,因为一些用户已经将此权限授予我的应用程序 - 我会然后问所有人并解释原因,这是我可以忍受的事情)。

As far as I know, what you want isn't possible. 据我所知,你想要的是不可能的。 In a similar question , there is a solution to detect system dialogs, but I don't think it will work for your overlay (only for the currently active activity). 在类似的问题中 ,有一个检测系统对话框的解决方案,但我不认为它适用于您的覆盖(仅适用于当前活动的活动)。

Another question suggests that it may be possible to monitor system dialogs via the ActivityManager class, but that API has been deprecated since LOLIPOP. 另一个问题表明,可以通过ActivityManager类监视系统对话框,但是自LOLIPOP以来该API已被弃用。

For these reasons, I suggest you to add a pause button to your overlay. 出于这些原因,我建议您在叠加层中添加一个暂停按钮。 Or even better, use a sticky notification with stop/start buttons so users can manually pause your overlay. 或者甚至更好, 使用带停止/启动按钮的粘性通知 ,以便用户可以手动暂停叠加。


To identify system apps, you need the package name as explained in this answer : 要识别系统应用程序,您需要包名称,如本答案中所述

 public boolean isSystemApp(String packageName) { try { // Get packageinfo for target application PackageInfo targetPkgInfo = mPackageManager.getPackageInfo( packageName, PackageManager.GET_SIGNATURES); // Get packageinfo for system package PackageInfo sys = mPackageManager.getPackageInfo( "android", PackageManager.GET_SIGNATURES); // Match both packageinfo for there signatures return (targetPkgInfo != null && targetPkgInfo.signatures != null && sys.signatures[0] .equals(targetPkgInfo.signatures[0])); } catch (PackageManager.NameNotFoundException e) { return false; } } 

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

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