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

查看:38
本文介绍了当我的应用程序进入后台时,如何防止 Android 截屏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建的应用程序要求该应用程序必须防止操作系统在出于安全原因将其推送到后台时截取该应用程序的屏幕截图.这样在应用之间切换时就看不到最后一个活动屏幕了.

The app I'm currently building has the requirement that the app has to prevent the OS to take a screenshot of the app when it's being pushed into the background for security reasons. This way it won't be able to see the last active screen when switching between apps.

我打算将此功能放在应用程序类的 onPause 方法中,但首先我需要找出如何实现此功能.

I'm planning to put this functionality in the application class's onPause method, but first I need to find out how I can achieve this functionality.

那么有没有人知道如何解决这个问题?

So is there anybody out there, that has a clue how to fix this?

推荐答案

尝试 FLAG_SECURE:

public class FlagSecureTestActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    setContentView(R.layout.main);
  }
}

这绝对可以防止来自 ICS 最近任务历史记录的手动屏幕截图和自动屏幕截图.它还可以防止屏幕录制(例如,使用媒体投影 API 的应用).

This definitely secures against manual screenshots and automatic screenshots from the ICS recent-tasks history. It also secures against screen recording (e.g., apps using the media projection APIs).

更新:它还可以保护 Android 6.0 上的 Now On Tap 或其他助手;如果用户打开助手,他们将无法访问您 UI 中的小部件和容器的详细信息.

UPDATE: it also secures against Now On Tap or other assistants on Android 6.0; they will not get access to the details of widgets and containers in your UI if the user brings up the assistant.

更新 #2:但是,并非活动中的所有内容都将受到保护.任何弹出窗口 —DialogSpinnerAutoCompleteTextView、操作栏溢出等—会没有安全感.您可以通过在其上调用 getWindow() 并设置 FLAG_SECURE 来修复 Dialog 问题.剩下的……变得棘手.有关更多信息,请参阅这篇博文.

UPDATE #2: however, not everything in the activity will be protected. Any pop-up windows — Dialog, Spinner, AutoCompleteTextView, action bar overflow, etc. — will be insecure. You can fix the Dialog problem by calling getWindow() on it and setting FLAG_SECURE. The rest... gets tricky. See this blog post for more.

这篇关于当我的应用程序进入后台时,如何防止 Android 截屏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆