防止录屏技术方案 - 1835434698/1835434698.github.io GitHub Wiki
概述:
防止直播被翻录的技术方案。
1、对于系统自带的截屏、三方的截屏、系统自带录屏软件。
1.1普通activity在setContentView()前添加
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
WindowManager.LayoutParams.FLAG_SECURE 官方文档:
Window flag: treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.
窗口标志:将窗口内容视为安全的,防止其出现在屏幕截图中或在非安全的显示器上被查看。
1.2、含有SurfaceView控件的需要设置 surfaceView.setSecure(true);
setSecure() 官方文档:
Control whether the surface view's content should be treated as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.
控制是否应将surface view的内容视为安全的,以防止其出现在屏幕快照中或在非安全的显示器上查看。
2、对于三方的录屏软件。
由于三方的录屏可以通过使用后台service运行,借助WindowManager在view上运行录屏。解决方案有三种。
2.1、WindowManager层阻止。
在没有root的情况下可以使用hook技术,但是只能阻止app内部的录屏,无法干预三方录屏。
2.2、获取正在运行的应用进程阻止。
由于activityManager.getRunningTasks()方法已经被官方废弃,并且只能得到自身应用和部分系统级应用。
由于activityManager.getRunningAppProcesses()方法在Android6.0以上已经被官方限制,只能得到自身应用。
此方案高版本无法使用。
2.3、获取在运行的service阻止。
可以通过使用activityManager.getRunningServices()获取到所有在运行的service,然后的到其包名。 然后在服务端维护一个录屏黑名单,定时检查是否在黑名单之中。