转自https://blog.csdn.net/dhl_1986/article/details/79073958
1 禁止截屏
出于安全考虑,我们需要对某些界面,比如二维码界面,登录界面禁止截屏。(像支付宝的付款二维码)
禁止截屏的代码很简单就一行,在Activity 生命初期的onCreate加上:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
这样你截屏的时候,系统会通知你截屏失败(华为是通知栏的方式),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.
*
* <p>See {@ android.view.Display#FLAG_SECURE} for more details about
* secure surfaces and secure displays.
*/
public static final int FLAG_SECURE = 0x00002000;
2 屏幕常亮
当我们用真机调试程序的时候,往往被锁屏烦恼,有一种办法比手动调节固定时间锁屏好用,在相应Activity 的初始周期onCreate 上加上:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
这样,当前界面就能保持常亮。FLAG_KEEP_SCREEN_ON 源码解释:
/** Window flag: as long as this window is visible to the user, keep
* the device\'s screen turned on and bright. */
public static final int FLAG_KEEP_SCREEN_ON = 0x00000080; 继续阅读与本文标签相同的文章
-
BAT技术面dubbo还能这么问?
2026-05-18栏目: 教程
-
yaml转json,json转yaml,使用js-yaml实现yaml和json转换
2026-05-18栏目: 教程
-
PostgreSQL系统隐藏字段
2026-05-18栏目: 教程
-
7月24日阿里云峰会.上海 开发者大会回看
2026-05-18栏目: 教程
-
aPaaS平台是什么?aPaaS与PaaS有什么区别?
2026-05-18栏目: 教程
