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

Merge branch 'dev1' into dev

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

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