Android iOS防录屏截屏

目录

    • Android防录屏和截屏
      • 关于WindowManager.LayoutParams.FLAG_SECURE
      • 关于Display.FLAG_SECURE
    • iOS防录屏和截屏
      • 监听截屏
      • 录屏监听


需求与安全总是对立的,有新的需求,就有新的接口开放,但随之而来的就是利用新接口或者新接口的使用者(app使用者)不按预期出牌。
简单说,我们打出了一把刀,有人用来切菜,有人用来砍柴,有人却用来行凶… 大概是这个意思,互联网软件行业特别多,尤其是破解、攻击。
言归正传,今天来探讨一下android和ios的防录屏。录屏接口的开放,ios和android开放都比较迟,早期系统都是没有的功能,但随着用户的需求,陆续都开放了录屏的接口。随之而来的就是应用安全-防录屏。典型的应用是金融、银行类的APP。

Android防录屏和截屏

Android比较容易,只需要在 Activity 的onCreate() 方法中添加一行代码:

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

一般情况下哪些activity不希望被截屏,添加上述代码,当然,多的话肯定是做一个BaseActivity,BaseActivity中加这行代码就可以。当这样的activity在前台时,用户启动截屏或录屏,系统会提示安全而不能截屏或录屏。从源头就断掉了录屏和截屏。

关于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.
*
*

See {@link android.view.Display#FLAG_SECURE} for more details about
* secure surfaces and secure displays.
*/
public static final int FLAG_SECURE = 0x00002000;

关于Display.FLAG_SECURE

**
* Display flag: Indicates that the display has a secure video output and
* supports compositing secure surfaces.
*


* If this flag is set then the display device has a secure video output
* and is capable of showing secure surfaces. It may also be capable of
* showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}.
*


* If this flag is not set then the display device may not have a secure video
* output; the user may see a blank region on the screen instead of
* the contents of secure surfaces or protected buffers.
*


* Secure surfaces are used to prevent content rendered into those surfaces
* by applications from appearing in screenshots or from being viewed
* on non-secure displays. Protected buffers are used by secure video decoders
* for a similar purpose.
*


* An application creates a window with a secure surface by specifying the
* {@link WindowManager.LayoutParams#FLAG_SECURE} window flag.
* Likewise, an application creates a {@link SurfaceView} with a secure surface
* by calling {@link SurfaceView#setSecure} before attaching the secure view to
* its containing window.
*


* An application can use the absence of this flag as a hint that it should not create
* secure surfaces or protected buffers on this display because the content may
* not be visible. For example, if the flag is not set then the application may
* choose not to show content on this display, show an informative error message,
* select an alternate content stream or adopt a different strategy for decoding
* content that does not rely on secure surfaces or protected buffers.
*


*
* @see #getFlags
*/
public static final int FLAG_SECURE = 1 << 1;

iOS防录屏和截屏

ios 主要是以监听状态。

监听截屏

UIApplication中仅有用户截屏后的通知,应用中只会收到已经截屏的通知并没办法干预(iOS8之后失效)。

// This notification is posted after the user takes a screenshot (for example by pressing both the home and lock screen buttons)
UIKIT_EXTERN NSNotificationName const UIApplicationUserDidTakeScreenshotNotification NS_AVAILABLE_IOS(7_0);

监听到之后进行处理:

-(void)viewDidAppear:(BOOL)animated{[super viewDidAppear:animated];[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(screenshots) name:UIApplicationUserDidTakeScreenshotNotification  object:nil];
}-(void)screenshots
{UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"[安全提醒]内含个人资金账户。不要截图,录制或分享给他人以保障资金账户安全。" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];[alert show];-(void)dealloc
{[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}

录屏监听

iOS 11 SDK 中新增了UIScreen的API用以告知应用当前屏幕正在录屏。当UIScreen.isCaptured 为true时,表示当前屏幕正在被录制、镜像或被Airplay 发送。

当录屏状态发生变化时,UIKit会发送UIScreenCapturedDidChange的notification。
基于此,我们可以在应用中接收此通知,来对用户的录屏行为做相应的处理

-(void)viewWillAppear:(BOOL)animated{[super viewWillAppear:animated];//检查当前设备是否处于录屏状态,这里应该是需要定时器来获取,否则只有加载的时候才会判断UIScreen * sc = [UIScreen mainScreen];if (@available(iOS 11.0, *)) {if (sc.isCaptured) {NSLog(@"录屏中");[self screenshots];}} else {}if (@available(iOS 11.0, *)) {
//注册通知,监测当前设备录屏状态发生变化[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(screenshots) name:UIScreenCapturedDidChangeNotification  object:nil];} else {}
}-(void) screenshots
{UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"正在录屏,请注意帐号密码安全问题" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];[alert show];
}-(void)dealloc
{if (@available(iOS 11.0, *)) {[[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenCapturedDidChangeNotification object:nil];} else {}
}

部分引用
https://www.jianshu.com/p/a94969ddd1dc

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/558247.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

work节点使用外部包_AFLSmart工具简单分析及使用介绍

AFLSmart 是一个在 AFL 基础上&#xff0c;结合了 Peach 的结构化输入组件的灰盒 smart fuzz 工具。AFLSmart 链接&#xff1a;https://github.com/aflsmart/aflsmart参考资料&#xff1a;《Smart Greybox Fuzzing》什么是 AFLSmart灰盒 smart fuzz灰盒测试是基于程序运行时刻的…

Android adb 启动APP

目录启动命令一 常规命令 包名/activity二 常规命令 包名命令关闭App获取包名和activity的路径代码获取1 命令获取( 需要app运行在前台&#xff0c;停留在启动界面)2命令获取(先执行命令&#xff0c;再点击app启动)启动命令 一 常规命令 包名/activity adb shell am start…

python语言使用什么语句实现上下文管理协议_Python 上下文管理器

上下文管理器在使用Python编程中&#xff0c;可以会经常碰到这种情况&#xff1a;有一个特殊的语句块&#xff0c;在执行这个语句块之前需要先执行一些准备动作&#xff1b;当语句块执行完成后&#xff0c;需要继续执行一些收尾动作。例如&#xff1a;当需要操作文件或数据库的…

Android日志[基础篇]Android Log日志输出

Android日志[基础篇]二 Android Studio修改LogCat日志的颜色 android.util.Log输出日志的常用方法如下&#xff1a; Log.v(String tag, String msg)Log.d(String tag, String msg)Log.i(String tag, String msg)Log.w(String tag, String msg)Log.e(String tag, String msg) …

python函数应用_python 函数应用

#函数的参数就是个变量#定义函数的时候&#xff0c;使用关键字参数&#xff0c;可以指定默认值def hello(namereboot,age1):return hello %s,your age is %s %(name,age)print hello(reboot,3)print hello(3,reboot)#print hello(age3,namereboot)print hello(reboot)def f(n):…

Android日志[基础篇]二 Android Studio修改LogCat日志的颜色

上一篇提到Android日志的5个级别的日志输出&#xff0c;在logcat里面设置自己喜欢或习惯的颜色&#xff0c;本文不只讲Android Sudio修改logcat的日志颜色。 代码和效果 代码 private void logColor(){Log.v(TAG,"logColor verbose");Log.d(TAG,"logColor de…

readfile函数使用方法_1分钟学会LOOKUP函数,有网友说使用这个方法,初学者秒变大神...

Hi&#xff0c;大家好&#xff0c;本专栏将会从零开始和大家用图文的方式&#xff0c;30天让你从不会到熟练使用函数&#xff0c;0基础开始学习Excel函数&#xff0c;让你喜欢上它&#xff01;有兴趣的小伙伴可以持续关注我&#xff0c;或者在专栏进行查看学习&#xff0c;愿与…

Android JNI Attempt to remove non-JNI local reference, dumping thread

Attempt to remove non-JNI local reference, dumping thread 解决办法&#xff1a; 去除Jni代码 env->DeleteLocalRef(javaObject);注意&#xff1a;是java层传递给jni层的对象不需用了DeleteLocalRef来进行对象删除&#xff0c;jni层创建的对象仍然需要保留代码。 这个…

背景图层和普通图层的区别_图层样式(一)—高级混合选项

一、图层顺序为了便于说明&#xff0c;首先建立例子&#xff0c;新建图层&#xff0c;用画笔随便画个圈&#xff0c;新建蒙版随便画一笔&#xff0c;然后把所有图层样式加给它。可以看到样式从上到下的顺序&#xff0c;这也是它们混合的图层顺序。图层顺序我的效果&#xff0c;…

Android9.0 http网络请求失败问题的处理

目录处理方法(任意一种)&#xff1a;APP改用https请求targetSdkVersion 降到27以下配置network-security-config&#xff08;推荐&#xff09;原因出错案例处理方法(任意一种)&#xff1a; APP改用https请求 这种方式是最佳方法&#xff0c;需要前后端协调&#xff0c;后端得…

代码里无图片地址_项目实战:爬高清图片

↑ 关注 星标 &#xff0c;后台回复【大礼包】送你2TPython自学资料好消息&#xff1a;Python学习交流群&#xff0c;已经建立&#xff0c;猛戳加入之前我发过一些爬虫的文章&#xff0c;不过一直没发过爬取图片的&#xff0c;今天就给大家分享一篇吧&#xff01;/1 前言/上篇…

Android TextView通过SpannableString设置字体、大小、颜色、样式、超级链接

代码应该都能看明白 public class MainActivity extends ActionBarActivity {private TextView tv, tv2;private SpannableString sStr, sStr2;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.act…

winform项目_winform项目——仿QQ即时通讯程序01:原理及项目分析

即时通讯程序&#xff0c;腾讯QQ可以说是一家独大&#xff0c;虽然市场上仍然有类似QQ的即时通讯程序&#xff0c;但是基本上面向的对象都是特定人群。那么&#xff0c;现在做一个即时通讯的软件还有意义吗&#xff1f;在我看来&#xff0c;意义非常大。作为一个学习编程的人&a…

Android面试基础一

Android面试基础二-原理及常见问题 目录1、四大组件1&#xff09;Activity2&#xff09;Service3&#xff09;ContentProvider4&#xff09;Broadcast Receiver2、四大组件的生命周期和简单用法1&#xff09;Activity2&#xff09;Service3&#xff09;BroadcastReceiver4&…

python怎么用大数据分析师_如何七周成为数据分析师18:Python的新手教程

本文是《怎样七周成为数据剖析师》的第十八篇教程&#xff0c;假定想要了解写作初衷&#xff0c;能够先行阅读七周指南。温馨提示&#xff1a;假定您曾经熟习Python&#xff0c;大可不用再看这篇文章&#xff0c;或只选择部分。Python是近年来最火爆的言语&#xff0c;曾经作为…

Android面试基础二-原理及常见问题

Android 面试基础一 目录Android源码相关分析1、Android属性动画实现原理2、补间动画实现原理3、Android各个版本API的区别4、Requestlayout&#xff0c;onlayout&#xff0c;onDraw&#xff0c;DrawChild区别与联系5、invalidate和postInvalidate的区别及使用6、Activity-Wind…

python数据展示库_收藏!盘点很实用的数据科学Python库

数据科学是一门研究数据并从中挖掘信息的学科。它不要求自创或学习新的算法&#xff0c;只需要知道怎么样研究数据并解决问题。这一过程的关键点之一就在于使用合适的库。本文概述了数据科学中常用的、并且有一定重要性的库。在进入正题之前&#xff0c;本文先介绍了解决数据科…

Android日志[进阶篇]二-分析堆栈轨迹(调试和外部堆栈)

Android日志[进阶篇]一-使用 Logcat 写入和查看日志 Android日志[进阶篇]二-分析堆栈轨迹(调试和外部堆栈) Android日志[进阶篇]三-Logcat命令行工具 Android日志[进阶篇]四-获取错误报告 Android日志[进阶篇]五-阅读错误报告 目录调试中的堆栈轨迹从外部来源打开堆栈轨迹监控剪…

python股票数据分析实验报告_Python实验报告

一、实验原理(要求、任务等)(一)、Python的开发环境Python诞生于20世纪90年代初&#xff0c;是一种解释型、面向对象、动态数据类型的高级程序设计语言&#xff0c;是最受欢迎的程序设计语言之一。编写、编译和运行Python程序有以下3种方法。1.使用交互式解释器2.使用Windows命…

Android日志[进阶篇]一-使用 Logcat 写入和查看日志

Android日志[进阶篇]一-使用 Logcat 写入和查看日志 Android日志[进阶篇]二-分析堆栈轨迹(调试和外部堆栈) Android日志[进阶篇]三-Logcat命令行工具 Android日志[进阶篇]四-获取错误报告 Android日志[进阶篇]五-阅读错误报告 目录查看应用日志写入日志消息Logcat 消息格式设置…