[英]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 问题
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: 我的问题:
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.
或者甚至更好, 使用带停止/启动按钮的粘性通知 ,以便用户可以手动暂停叠加。
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.