如何在 Nativescript 移动应用程序中禁用屏幕截图? [英] How disable screenshots in Nativescript mobile application?

查看:71
本文介绍了如何在 Nativescript 移动应用程序中禁用屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在原生Android应用中禁用screenhors需要添加代码

In native Android application for disabling screenshors need to add code

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

但是如何在 NativeScript 应用程序中使用这个安全选项?

but how use this security option in NativeScript application?

推荐答案

本方案是在Nativescript-Vue中完成的,请根据您使用的Nativescript的variant进行调整.

This solution is done in Nativescript-Vue, please adjust it according to the varient of Nativescript you use.

导入这些:

import { isAndroid, isIOS, device, screen} from "tns-core-modules/platform";
const app = require("tns-core-modules/application");

添加 pageLoad 函数以在页面加载时执行代码:

Add a pageLoad function to execute code on page load :

<Page @loaded="pageLoad">

运行此代码:

pageLoad: function() {
    if (isAndroid) {
      if (app.android && device.sdkVersion >= '21') {
        const window = app.android.startActivity.getWindow();
        window.setFlags(android.view.WindowManager.LayoutParams.FLAG_SECURE,
                     android.view.WindowManager.LayoutParams.FLAG_SECURE);
      }
    }
}

我亲自测试过,基本上是导入变量,并在页面加载或创建的页面上运行上面提供的代码.

Personally tested by me, basically import the variables, and run the code provided above on pageload or on page created.

这是我在 StackOverflow 上的第一个回答 :)

This is my first answer on StackOverflow :)

这篇关于如何在 Nativescript 移动应用程序中禁用屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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