Android - Couldn't capture screenshot

   Screen capture of quite a few android applications after updates have started failing. Attempts to use developer tools like ddms, Android Studio too doesn't help. On device screen capture ( power + volume down ) fails claiming either limited storage space or denial by the app or organization. This is noticeable in Netflix. Screen capture works fine in all sections of the app but fails only in the playback view. This kind of rules out limited storage or device specific issues. Netflix has some explicit logic to disable screen capture during playback which makes sense as they probably want to protect their content. This is even more applicable for applications like Snapchat where in the message is destroyed and users shouldn't be able to capture the screen contents.



   So how does this work? Turns out, Android has a public API FLAG_SECURE for windows. Application developers can request for the window to be secure upon activity creation.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().addFlags( WindowManager.LayoutParams.FLAG_SECURE );

}

 Application developers can even extend the same feature to their dialogs. Dialog like Activity too have a window associated with them and expose the same getWindow() API.

No comments: