Prevent application with SYSTEM_ALERT_WINDOW from obscuring my application

流过昼夜 提交于 2019-12-06 11:15:25

Even if it's not exactly what you're asking, the closest replacement I know of is:

Later can be implemented like so:

override fun onFilterTouchEventForSecurity(event: MotionEvent): Boolean {
    if ((event.flags and MotionEvent.FLAG_WINDOW_IS_OBSCURED) == MotionEvent.FLAG_WINDOW_IS_OBSCURED) {
        Toast.makeText(context, "Screen overlay detected!", Toast.LENGTH_LONG).show()
        return false // touch event is cancelled
    }
    return super.onFilterTouchEventForSecurity(event)
}

See also the Security section of View class documentation.

Notice that this functionality is available from API 9+. A workaround for older APIs can be found in this SO Question: Analogue of android:filterTouchesWhenObscured for API level below 9.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!