Android detect or block floating/overlaying apps
Asked Answered
E

1

26

Android enables apps to draw over other apps with android.permission.SYSTEM_ALERT_WINDOW and it's called a floating/overlaying app. For example Facebook Messenger has always visible chat bubbles at the edges of screen.

My question is: Is it possible to detect or block in Java code any app which draws over my app?

Eyeshot answered 28/4, 2016 at 18:58 Comment(3)
On newer versions you can ask fro screen recording permission, and compare what you draw and what is on the screenTrigeminal
filterTouchesWhenObscured on view level set to true would also fix the issueBuffet
I've created a sample to show all ways to detect: https://mcmap.net/q/537454/-how-do-apps-detect-that-saw-permission-is-currently-being-usedPsoriasis
Y
15

There is a View#onFilterTouchEventForSecurity() method you can override to detect if the motion event has the FLAG_WINDOW_IS_OBSCURED. This will let you know if something is drawn on top of your view.

@Override
public boolean onFilterTouchEventForSecurity(MotionEvent event) {
    if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) == MotionEvent.FLAG_WINDOW_IS_OBSCURED){
        // show error message
        return false;
    }
    return super.onFilterTouchEventForSecurity(event);
}

If you just want to protect your app from tap jacking due to another app drawing over your app you can add setFilterTouchesWhenObscured to your views via XML or programmatically.

Yearround answered 8/9, 2016 at 0:7 Comment(2)
It doesn't work with facebook messenger bubble detection. But according to docs - it's the only way. #Android...Lucindalucine
Here are all ways to detect it: https://mcmap.net/q/537454/-how-do-apps-detect-that-saw-permission-is-currently-being-usedPsoriasis

© 2022 - 2024 — McMap. All rights reserved.