20

Basically i want VIDEO PIRACY PROTECTION

My application has video streaming and I want to protect my video streaming from other applications. Other applications should not be able to capture screen while my video is playing. Any suggestions how can i achieve this.. Thanks in advance.

Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
Ajay
  • 552
  • 2
  • 4
  • 16

3 Answers3

50

You can secure screen capturing functionality by adding FLAG_SECURE into your Activity as follows

  getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); 

Check this link which says

Screen capturing and sharing

Android 5.0 lets you add screen capturing and screen sharing capabilities to your app with the new android.media.projection APIs. This functionality is useful, for example, if you want to enable screen sharing in a video conferencing app.

The new createVirtualDisplay() method allows your app to capture the contents of the main screen (the default display) into a Surface object, which your app can then send across the network. The API only allows capturing non-secure screen content, and not system audio. To begin screen capturing, your app must first request the user’s permission by launching a screen capture dialog using an Intent obtained through the createScreenCaptureIntent() method.

Also documentation at this link says that

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

Above solution will surely prevent applications from capturing Video of your app

silwar
  • 6,470
  • 3
  • 46
  • 66
  • I know this solution works for capturing screen shot. But is it works for video capturing also?? – Ajay Jun 03 '15 at 10:53
  • @Ajay: Either this works or what you want is not supported. So, try it yourself. – CommonsWare Jun 03 '15 at 11:41
  • 1
    This works fine for video & screenshots. But not able to restrict audio recording. Still audio recorded by other apps. – Ranjithkumar Oct 03 '17 at 12:41
  • @RanjithKumar LayoutParams.FLAG_SECURE is for window object only so it can prevent video and screenshots capturing. For restricting audio recording, you have to search for different solution – silwar Oct 04 '17 at 05:50
  • 1
    Why the h*ll no one mentions where are we supposed to place that line? –  Jun 05 '19 at 19:59
  • @silwar I tried using the FLAG and it works fine with most of the screen recorder apps. But [DU Recorder](https://play.google.com/store/apps/details?id=com.DUrecorder.screenrecorder.videorecorde&hl=en_IN&gl=US) somehow manages to record the screen using floating window. Can you help me out? – Rahul Khurana Dec 14 '20 at 15:34
  • @RahulKhurana I will check and let you know if there is any solution for this – silwar Dec 15 '20 at 14:58
  • hi @silwar, did you get the time to check? – Rahul Khurana Dec 24 '20 at 14:00
  • hi @RahulKhurana I am going to help you check. Can you send the app (DU Recorder) to me? Preferably the APK file. It seems like it was removed from Google Play. – FEBRYAN ASA PERDANA Aug 01 '21 at 08:00
8
  getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);

write above setContenView();

It prevents only snapshot capturing. And also prevents video capturing. But For video capturing its device specific.

arshad shaikh
  • 673
  • 8
  • 11
  • 1
    Any idea how to prevent video capturing for all devices? – techniqez Apr 10 '17 at 11:42
  • I am having issues with [DU Recorder](https://play.google.com/store/apps/details?id=com.DUrecorder.screenrecorder.videorecorde&hl=en_IN&gl=US), who somehow manages to record the screen. Can you help? – Rahul Khurana Dec 14 '20 at 15:37
2

Try adding this in your Activity,

getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); 
siriscac
  • 1,699
  • 12
  • 21