提交 07c6275e 编写于 作者: lizhongyi_'s avatar lizhongyi_

Merge branch 'dev1' into dev

* dev1:
  uni-usercapturescreen Android 新增禁止截屏API

# Conflicts:
#	pages/index/index.vue
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
<button @tap="testScreenShotListen">开启截屏监听</button>
<button @tap="testScreenShotOff">关闭截屏监听</button>
<button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
<button @tap="testShowModal">模态弹窗</button>
<button @tap="testShowModalWithTF">模态弹窗带输入框</button>
<button @tap="testStartWifi">初始化wifi模块</button>
<button @tap="testGetWifiList">获取当前wifi列表</button>
<button @tap="testGetConnnectWifi">获取当前连接的wifi</button>
<button @tap="testConnnectWifi">链接wifi</button>
<button @tap="testStopWifi">关闭wifi模块</button>
</view>
</template>
<script>
import showModal from '@/uni_modules/uni-showmodal';
export default {
data() {
return {
title: 'Hello',
memListener: null,
}
},
onLoad() {
},
methods: {
onMemoryWarning: function(res) {
console.log(res);
},
testShowModal() {
showModal({
title: "温馨提示",
content: "这是一个模态弹窗",
cancelColor: "#ff0000",
confirmColor: "#00ff00",
showCancel: true,
success: function(res) {
console.log(res)
}
})
},
testShowModalWithTF() {
showModal({
title: "提示",
content: "带输入框的弹窗",
showCancel: false,
editable: true,
placeholderText: "请输入内容",
success: function(res) {
console.log(res)
}
})
},
testConnnectWifi() {
uni.connectWifi({
maunal: false,
SSID: "Xiaomi_20D0",
password: "BBBB",
complete: (res) => {
console.log(res);
}
});
},
testGetConnnectWifi() {
uni.getConnectedWifi({
partialInfo: false,
complete: (res) => {
console.log(res);
if (res.errCode == 0) {
uni.showToast({
icon: 'none',
title: res.wifi.SSID
})
} else {
uni.showToast({
icon: 'none',
title: res.errMsg
})
}
}
});
},
testStartWifi() {
uni.startWifi({
success: (res) => {
console.log("success: " + JSON.stringify(res));
// wifi 开启成功后,注册wifi链接状态监听和wifi列表获取监听
uni.onGetWifiList(function(res) {
console.log("onGetWifiList");
console.log(res);
});
uni.onWifiConnected(function(res) {
console.log("onWifiConnected");
console.log(res);
});
uni.onWifiConnectedWithPartialInfo(function(res) {
console.log("onWifiConnectedWithPartialInfo");
console.log(res);
});
},
fail: (res) => {
console.log("fail: " + JSON.stringify(res));
},
complete: (res) => {
console.log("complete: " + JSON.stringify(res));
}
})
},
testStopWifi() {
uni.stopWifi({
success: (res) => {
console.log("success: " + JSON.stringify(res));
},
fail: (res) => {
console.log("fail: " + JSON.stringify(res));
},
complete: (res) => {
console.log("complete: " + JSON.stringify(res));
}
})
},
testGetWifiList() {
uni.getWifiList({
success: (res) => {
console.log("success: " + JSON.stringify(res));
},
fail: (res) => {
console.log("fail: " + JSON.stringify(res));
},
complete: (res) => {
console.log("complete: " + JSON.stringify(res));
}
})
},
testonMemoryWarning() {
uni.onMemoryWarning(this.onMemoryWarning)
uni.showToast({
icon: 'none',
title: '已监听,注意控制台输出'
})
},
testoffMemoryWarning() {
uni.offMemoryWarning(this.onMemoryWarning)
uni.showToast({
icon: 'none',
title: '监听已移除'
})
},
testScreenShotListen() {
var that = this;
uni.onUserCaptureScreen(function(res) {
console.log(res);
if (uni.getSystemInfoSync().platform == "android") {
// 除android 之外的平台,不需要判断返回状态码
if (res.errCode == -1) {
// 启动失败
return;
} else if (res.errCode == 0) {
uni.showToast({
icon: "none",
title: '截屏监听已开启'
})
} else {
uni.showToast({
icon: "none",
title: '捕获截屏事件'
})
that.screenImage = res.image
}
} else {
// 除android 之外的平台,不需要判断返回状态码
uni.showToast({
icon: "none",
title: '捕获截屏事件'
})
}
});
if (uni.getSystemInfoSync().platform != "android") {
// 除android 之外的平台,直接提示监听已开启
uni.showToast({
icon: "none",
title: '截屏监听已开启'
})
}
},
testScreenShotOff() {
uni.offUserCaptureScreen(function(res) {
console.log(res);
});
// 提示已经开始监听,注意观察
uni.showToast({
icon: "none",
title: '截屏监听已关闭'
})
},
testGetBatteryInfo() {
uni.getBatteryInfo({
success(res) {
console.log(res);
uni.showToast({
title: "当前电量:" + res.level + '%',
icon: 'none'
});
}
})
},
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
<button @tap="testScreenShotListen">开启截屏监听</button>
<button @tap="testScreenShotOff">关闭截屏监听</button>
<button @tap="testSetUserCaptureScreen">{{setUserCaptureScreenText}}</button>
<button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
<button @tap="testStartWifi">初始化wifi模块</button>
<button @tap="testGetWifiList">获取当前wifi列表</button>
<button @tap="testGetConnnectWifi">获取当前连接的wifi</button>
<button @tap="testConnnectWifi">链接wifi</button>
<button @tap="testStopWifi">关闭wifi模块</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello',
memListener:null,
setUserCaptureScreenFlag: true,
setUserCaptureScreenText: '禁止截屏'
}
},
onLoad() {
},
methods: {
onMemoryWarning:function(res){
console.log(res);
},
testConnnectWifi(){
uni.connectWifi({
maunal:false,
SSID:"Xiaomi_20D0",
password:"BBBB",
complete:(res)=>{
console.log(res);
}
});
},
testGetConnnectWifi(){
uni.getConnectedWifi({
partialInfo:false,
complete:(res)=>{
console.log(res);
if (res.errCode == 0) {
uni.showToast({
icon:'none',
title:res.wifi.SSID
})
} else{
uni.showToast({
icon:'none',
title:res.errMsg
})
}
}
});
},
testStartWifi(){
uni.startWifi({
success:(res)=> {
console.log("success: " + JSON.stringify(res));
// wifi 开启成功后,注册wifi链接状态监听和wifi列表获取监听
uni.onGetWifiList(function(res){
console.log("onGetWifiList");
console.log(res);
});
uni.onWifiConnected(function(res){
console.log("onWifiConnected");
console.log(res);
});
uni.onWifiConnectedWithPartialInfo(function(res){
console.log("onWifiConnectedWithPartialInfo");
console.log(res);
});
},fail:(res)=>{
console.log("fail: " + JSON.stringify(res));
},complete:(res)=>{
console.log("complete: " + JSON.stringify(res));
}
})
},
testStopWifi() {
uni.stopWifi({
success:(res)=> {
console.log("success: " + JSON.stringify(res));
},fail:(res)=>{
console.log("fail: " + JSON.stringify(res));
},complete:(res)=>{
console.log("complete: " + JSON.stringify(res));
}
})
},
testGetWifiList() {
uni.getWifiList({
success:(res)=> {
console.log("success: " + JSON.stringify(res));
},fail:(res)=>{
console.log("fail: " + JSON.stringify(res));
},complete:(res)=>{
console.log("complete: " + JSON.stringify(res));
}
})
},
testonMemoryWarning() {
uni.onMemoryWarning(this.onMemoryWarning)
uni.showToast({
icon:'none',
title:'已监听,注意控制台输出'
})
},
testoffMemoryWarning(){
uni.offMemoryWarning(this.onMemoryWarning)
uni.showToast({
icon:'none',
title:'监听已移除'
})
},
testScreenShotListen() {
var that = this;
uni.onUserCaptureScreen(function(res) {
console.log(res);
if (uni.getSystemInfoSync().platform == "android") {
// 除android 之外的平台,不需要判断返回状态码
if(res.errCode == -1){
// 启动失败
return ;
}else if(res.errCode == 0){
uni.showToast({
icon:"none",
title:'截屏监听已开启'
})
}else {
uni.showToast({
icon:"none",
title:'捕获截屏事件'
})
that.screenImage = res.image
}
}else{
// 除android 之外的平台,不需要判断返回状态码
uni.showToast({
icon:"none",
title:'捕获截屏事件'
})
}
});
if (uni.getSystemInfoSync().platform != "android") {
// 除android 之外的平台,直接提示监听已开启
uni.showToast({
icon:"none",
title:'截屏监听已开启'
})
}
},
testScreenShotOff() {
uni.offUserCaptureScreen(function(res) {
console.log(res);
});
// 提示已经开始监听,注意观察
uni.showToast({
icon:"none",
title:'截屏监听已关闭'
})
},
testGetBatteryInfo() {
uni.getBatteryInfo({
success(res) {
console.log(res);
uni.showToast({
title: "当前电量:" + res.level + '%',
icon: 'none'
});
}
})
},
testSetUserCaptureScreen() {
let flag = this.setUserCaptureScreenFlag;
uni.setUserCaptureScreen({
open: flag,
success: (res) => {
console.log("setUserCaptureScreen open: " + flag + " success: " + JSON.stringify(res));
},
fail: (res) => {
console.log("setUserCaptureScreen open: " + flag + " fail: " + JSON.stringify(res));
},
complete: (res) => {
console.log("setUserCaptureScreen open: " + flag + " complete: " + JSON.stringify(res));
}
});
uni.showToast({
icon:"none",
title: this.setUserCaptureScreenText
});
this.setUserCaptureScreenFlag = !this.setUserCaptureScreenFlag;
if (this.setUserCaptureScreenFlag) {
this.setUserCaptureScreenText = '禁止截屏';
} else {
this.setUserCaptureScreenText = '允许截屏';
}
},
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
......@@ -34,7 +34,8 @@
"uni-ext-api":{
"uni": {
"onUserCaptureScreen": "onUserCaptureScreen",
"offUserCaptureScreen": "offUserCaptureScreen"
"offUserCaptureScreen": "offUserCaptureScreen",
"setUserCaptureScreen": "setUserCaptureScreen"
}
},
"dependencies": [],
......
......@@ -13,7 +13,17 @@ import FileObserver from "android.os.FileObserver";
import File from "java.io.File";
import Environment from "android.os.Environment";
import System from 'java.lang.System';
import WindowManager from 'android.view.WindowManager';
/**
* setUserCaptureScreen 参数定义
*/
type SetUserCaptureScreenOption = {
open: boolean;
success?: (res: UTSJSONObject) => void;
fail?: (res: UTSJSONObject) => void;
complete?: (res: UTSJSONObject) => void;
}
/**
......@@ -145,5 +155,41 @@ export function offUserCaptureScreen(success: (res: any) => void) {
success({});
}
/**
* 设置是否禁止截屏
*/
export function setUserCaptureScreen(option: SetUserCaptureScreenOption) {
const res = {
errCode: 0,
errMsg: "setUserCaptureScreen:ok",
errSubject: "uni-setUserCaptureScreen"
};
UTSAndroid.getUniActivity()?.runOnUiThread(new SetUserCaptureScreenRunnable(option.open));
option.success?.(res);
option.complete?.(res);
}
class SetUserCaptureScreenRunnable extends Runnable {
/**
* true 表示禁止截屏
* false 表示允许截屏
*/
private open: boolean = false;
constructor(open: boolean) {
super();
this.open = open;
}
override run(): void {
if (this.open) {
UTSAndroid.getUniActivity()?.getWindow()?.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
UTSAndroid.getUniActivity()?.getWindow()?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册