简体   繁体   English

防止在Android中拍摄屏幕截图

[英]Prevent taking a screenshot in android

i used the below link to prevent to take screenshot but this will take more time to prevent taking the screenshot after executing the code which is going to prevent the taking of screenshot. 我使用下面的链接来防止截屏,但是执行代码后将花费更多的时间来防止截屏,这将阻止截屏。

How do I prevent Android taking a screenshot when my app goes to the background? 当我的应用程序进入后台时,如何防止Android截屏?

Code: 码:

if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}

Phone: galaxy s6 Os: 5.1.1 电话:galaxy s6操作系统:5.1.1

This code is intended to mark an Activity (or more precise, a Window) as "Secure" not the phone. 此代码旨在将Activity (或更准确地说是窗口)标记为“安全”,而不是电话。 It only prevents the Activity in which this flag has been set from having its screenshot taken. 它仅防止设置了该标志的Activity获取其屏幕截图。

To secure an Activity , call this code in the OnCreate . 要保护Activity ,请在OnCreate调用此代码。 This will not stop screenshots when the Activity is not displayed. 不显示Activity时,这不会停止屏幕截图。

Example: 例:

@Override
protected void onCreate(Bundle b) {
    super.onCreate(b);

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

}

I haven't tried it myself so do not know if it is possible but you could perhaps draw an invisible window on top of the current Activity that has the SECURE flag set. 我自己还没有尝试过,所以不知道是否可能,但是您可能会在设置了SECURE标志的当前活动之上绘制一个不可见的窗口。 Maybe this would prevent screenshots of the whole phone which I think is what you are asking. 也许这样可以防止整个手机的屏幕截图,我想这就是您要的。

Just add this line: 只需添加以下行:

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

Before your setContentView() method. 在setContentView()方法之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM