我如何prevent的Andr​​oid获取屏幕截图时,我的应用程序去的背景是什么?我的、截图、应用程序、屏幕

2023-09-11 12:35:04 作者:恍如夢境

该应用程序,我目前正在建设具有应用程序有prevent该操作系统利用该应用程序的截图时,它的被推到后台出于安全原因的要求。这将无法应用程序之间切换的时候,看到最后一个活动的屏幕这样。

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(LayoutParams.FLAG_SECURE,
                         LayoutParams.FLAG_SECURE);

    setContentView(R.layout.main);
  }
}

这绝对保证免受来自ICS近期任务的历史手动截图和自动截屏。

This definitely secures against manual screenshots and automatic screenshots from the ICS recent-tasks history.

更新:这也保证了对现在在Android上6.0轻触或其它助剂;他们将不能访问部件和集装箱在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.