简体   繁体   English

如何防止用户在 Android Crosswalk WebView 中截取屏幕截图?

[英]How to prevent a user from taking a screenshot in Android Crosswalk WebView?

I'm trying to prevent from taking a screenshot in Crosswalk WebView.我试图防止在 Crosswalk WebView 中截取屏幕截图。 I have tried PrivacyScreenPlugin .我试过PrivacyScreenPlugin This plugin works very good when I wasn't using Crosswalk plugin.当我不使用 Crosswalk 插件时,这个插件效果很好。 However, if I added Crosswalk plugin, it only works at the app launch time.但是,如果我添加了 Crosswalk 插件,它只能在应用程序启动时工作。
For example, when I launch my app, I can not take a screenshot.例如,当我启动我的应用程序时,我无法截取屏幕截图。 However, if I show any other UI component (such as volume control, etc..), my app start allowing to take a screenshot.但是,如果我显示任何其他 UI 组件(例如音量控制等),我的应用程序开始允许截取屏幕截图。

I found this related question and one person mentioned that if I use Crosswalk, I need to modify PrivacyScreenPlugin/Crosswalk.我发现了这个相关的问题,有人提到如果我使用 Crosswalk,我需要修改 PrivacyScreenPlugin/Crosswalk。

Here is what I tried:这是我尝试过的:
In Crosswalk WebView plugin, XwalkWebViewEngine#init method.在 Crosswalk WebView 插件中,XwalkWebViewEngine#init 方法。

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

However, above code wasn't fix my issue.但是,上面的代码并没有解决我的问题。
And, I couldn't find a place to modify in PrivacyScreenPlugin.而且,我在 PrivacyScreenPlugin 中找不到修改的地方。

I'm using following Android versions and plugins:我正在使用以下 Android 版本和插件:

  • Android 5.0.2安卓 5.0.2
  • Crosswalk plugin 1.6.1人行横道插件 1.6.1
  • PrivacyScreenPlugin 0.2.0隐私屏幕插件 0.2.0

Any comment would be appreciated.任何评论将不胜感激。

According to this ticket.根据这张票。 There is a temporary workaround to avoid this issue.有一个临时解决方法可以避免此问题。

In AndroidManifest.xml:在 AndroidManifest.xml 中:
Replace代替

android:theme="@android:style/Theme.Black.NoTitleBar" android:theme="@android:style/Theme.Black.NoTitleBar"

with

android:theme="@android:style/Theme.Holo.Light.NoActionBar" android:theme="@android:style/Theme.Holo.Light.NoActionBar"

This workaround worked for me.这个解决方法对我有用。 It basically digs to the SurfaceView that XWalkView creates and makes it secure:它基本上挖掘了 XWalkView 创建的 SurfaceView 并使其安全:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    ((SurfaceView)((FrameLayout)((FrameLayout) mXWalkView.getChildAt(0)).getChildAt(0)).getChildAt(0)).setSecure(true);
}

Looks ugly but worked like a charm.看起来很丑,但效果很好。

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

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