简体   繁体   中英

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. 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.

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; } } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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