简体   繁体   English

如何在android中检测屏幕叠加?

[英]How to detect screen overlay in android?

In some devices, there is no action when click vpn permission ok button, while screen overlay application is running. 在某些设备中,当屏幕覆盖应用程序正在运行时,单击vpn权限确定按钮时没有任何操作。 So i want to check screen overlay application is running, and make 'Screen Overay detected' dialog. 所以我想检查屏幕覆盖应用程序是否正在运行,并使'Screen Overay detected'对话框。

Is there anyway to detect screen overlay programmatically in android? 无论如何在android中以编程方式检测屏幕叠加?

Sample code 示例代码

public void checkDrawOverlayPermission(Context context) {
    // check if we already  have permission to draw over other apps
    if (Settings.canDrawOverlays(context)) {
        // code
    } else {
        // if not construct intent to request permission
        final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + getPackageName()));
        // request permission via start activity for result
        startActivityForResult(intent, REQUEST_CODE);
    }
}

Inside onActivityResult check permission again 在onActivityResult内部再次检查权限

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // check if received result code
    // is equal our requested code for draw permission
    if (requestCode == REQUEST_CODE) {
        // if so check once again if we have permission
         if (Settings.canDrawOverlays(this)) {
        // continue here - permission was granted

    }
    }
}

And if u want to handle Screen Overlay Detected PopUp Programatically? 如果你想以编程方式处理Screen Overlay Detected PopUp? This should help, https://gist.github.com/Aeonitis/2337b1ca652173839395be82db7d05c3 这应该有帮助, https://gist.github.com/Aeonitis/2337b1ca652173839395be82db7d05c3

Use Lint (on menu go to Analyze > Inspect Code...). 使用Lint(在菜单上转到Analyze> Inspect Code ...)。 If there is any screen overlay on your project, it will tell you. 如果您的项目有任何屏幕覆盖,它会告诉您。

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

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