Skip to content Skip to sidebar Skip to footer

Stop Pre-installed Screen Recording Apps From Recording Screen In Android

I am using flutter and have disabled normal apps from recording the screen. Here is the code getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams

Solution 1:

As far as I'm aware, there is no official way to universally prevent screen grabs/recordings.

This is because FLAG_SECURE just prevents capturing on non-secure displays:

Window flag: treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.

But apps that have elevated permissions can create a secure virtual display and use screen mirroring to record your screen, which does not respect the secure flag.

Read this article for more info:

That would mean that an Android device casting to a DRM-protected display like a TV would always display sensitive screens, since the concept of secure really means “copyrighted”. For apps, Google forestalled this issue by preventing apps not signed by the system key from creating virtual “secure” displays

Regarding how some apps still manage to do it, you could try these:

  • Check if there are any external/virtual displays connected, and hide/show your content based on that. see this
  • Don't show your content on rooted devices

Solution 2:

Adding this code to my MainActivity.java solved the problem:

protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!this.setSecureSurfaceView()) {
        Log.e("MainActivity", "Could not secure the MainActivity!");
    }

}



privatefinal boolean setSecureSurfaceView() {
    ViewGroup content = (ViewGroup) this.findViewById(android.R.id.content);
    //Intrinsics.checkExpressionValueIsNotNull(content, "content");if (!this.isNonEmptyContainer((View) content)) {
        returnfalse;
    } else {
        View splashView = content.getChildAt(0);
        //Intrinsics.checkExpressionValueIsNotNull(splashView, "splashView");if (!this.isNonEmptyContainer(splashView)) {
            returnfalse;
        } else {
            View flutterView = ((ViewGroup) splashView).getChildAt(0);
            //Intrinsics.checkExpressionValueIsNotNull(flutterView,          "flutterView");if (!this.isNonEmptyContainer(flutterView)) {
                returnfalse;
            } else {
                View surfaceView = ((ViewGroup) flutterView).getChildAt(0);
                if (!(surfaceView instanceof SurfaceView)) {
                    returnfalse;
                } else {
                    ((SurfaceView) surfaceView).setSecure(true);
                    this.getWindow().setFlags(8192, 8192);
                    returntrue;
                }
            }
        }
    }

}

    privatefinal boolean isNonEmptyContainer(View view) {
        if (!(view instanceof ViewGroup)) {
            returnfalse;
        } else {
            return ((ViewGroup) view).getChildCount() >= 1;
        }
}

Import the required things.

Post a Comment for "Stop Pre-installed Screen Recording Apps From Recording Screen In Android"