如何在最近使用的屏幕上隐藏应用程序内容,同时允许在具有非标准导航手势的手机上进行屏幕截图?

Jol*_*151 7 android privacy

从最近使用的屏幕中隐藏应用程序内容的最直接且兼容的方法是使用FLAG_SECURE,它可以从最近使用的屏幕中隐藏应用程序内容,停止记录屏幕,并停止截取屏幕截图等。我只想从最近使用的屏幕中隐藏应用程序内容,同时允许所有其他操作。

这里的其他答案建议在这两个活动中设置标志onPause()并将其删除。onResume()这在大多数手机上都可以正常工作,但在某些手机上,例如我的 Android 9 上的 OnePlus 和我的同事 Android 10 上的 Moto G,除了 3 个底部按钮和药丸导航的标准选项之外,制造商还实现了自定义导航手势。使用这些自定义形式的导航时,应用程序会调用onPause(),但设置FLAG_SECURE不会在最近使用的屏幕上隐藏应用程序内容。

这是我的代码:

    override fun onPause() {
        super.onPause()
        // Set secure flag so the multitasking screen doesn't show the app contents
        // Need to clear on resume because this also stops screenshots from being taken
        window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
    }

    override fun onResume() {
        super.onResume()
        // Clear secure flag so the app is able to take screenshots
        window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
    }

Run Code Online (Sandbox Code Playgroud)

我也尝试在调用之前设置标志super,但无济于事,如以下代码所示:

    override fun onPause() {
        // Set secure flag so the multitasking screen doesn't show the app contents
        // Need to clear on resume because this also stops screenshots from being taken
        window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
        
        super.onPause()
    }

    override fun onResume() {
        // Clear secure flag so the app is able to take screenshots
        window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
        
        super.onResume()
    }
Run Code Online (Sandbox Code Playgroud)

我倾向于认为这是制造商未正确处理自定义导航状态更改的错误,但我发现道明银行应用程序(无需登录)实际上按预期工作,允许使用屏幕截图并且操作系统在进入后台时正确隐藏应用程序内容。

有任何想法吗?