diff --git a/pages/SystemAPI/android/screenlisten.vue b/pages/SystemAPI/android/screenlisten.vue index 75b446af8abd82ef244ad824629e90017955b7a8..81b4e09bf0ea696b9928a128721bbd3be2f213c9 100644 --- a/pages/SystemAPI/android/screenlisten.vue +++ b/pages/SystemAPI/android/screenlisten.vue @@ -37,7 +37,7 @@ var that = this; onUserCaptureScreen(function(res) { console.log(res); - that.screenImage = res + that.screenImage = res.image uni.showToast({ icon:"none", title:'截屏捕捉成功' diff --git a/uni_modules/uts-advance/utssdk/app-android/index.uts b/uni_modules/uts-advance/utssdk/app-android/index.uts index ae52cb01e3280e9e8632903f840eda57f2784a7e..2d82bc1c0b564d60731ef6acc53d0735685ab656 100644 --- a/uni_modules/uts-advance/utssdk/app-android/index.uts +++ b/uni_modules/uts-advance/utssdk/app-android/index.uts @@ -105,7 +105,7 @@ class RemoveUIRunnable extends Runnable { override run():void { - let decorView = getUniActivity()!.window.decorView; + let decorView = getUniActivity()!.getWindow().getDecorView(); let frameContent = decorView.findViewById(android.R.id.content) let targetTV = frameContent.findViewWithTag("helloText") diff --git a/uni_modules/uts-nativepage/utssdk/app-android/index.uts b/uni_modules/uts-nativepage/utssdk/app-android/index.uts index c2a5ac1d69d1f152a57dfba75ce2839fe72d4ce5..392db82b0551bf841e74de7b0f726d80a43a49ad 100644 --- a/uni_modules/uts-nativepage/utssdk/app-android/index.uts +++ b/uni_modules/uts-nativepage/utssdk/app-android/index.uts @@ -24,7 +24,6 @@ import { import Service from 'android.app.Service'; import System from 'java.lang.System'; -import WindowManager from 'android.view.WindowManager'; class ForeService extends Service { diff --git a/uni_modules/uts-screenshot-listener/utssdk/app-android/index.uts b/uni_modules/uts-screenshot-listener/utssdk/app-android/index.uts index 96808cf8ac83ba0a9065a5e1f4e7d1f5b25d899c..10b44037b3231288cafe18f9a25e042330521a41 100644 --- a/uni_modules/uts-screenshot-listener/utssdk/app-android/index.uts +++ b/uni_modules/uts-screenshot-listener/utssdk/app-android/index.uts @@ -14,26 +14,52 @@ import File from "java.io.File"; import Environment from "android.os.Environment"; + +/** + * 文件监听器 + */ +let screenOB: ScreenFileObserver | null = null; +/** + * 记录文件监听器上次监听的时间戳,避免重复监听 + */ +let lastFileObserverTime: number = 0; +/** + * 图片捕捉定义 + */ +type OnImageCatchOptions = { + onImageCatchChange: (res: any) => void; +}; /** - * android 10版本以上通过文件监听实现 + * 图片捕捉监听变量 + */ +let listenOption = new OnImageCatchOptions(); + + + +/** + * android 文件监听实现 */ class ScreenFileObserver extends FileObserver { + /** + * 所有截屏文件的存放目录 + */ allScreen: File; constructor(screenFile: string) { super(screenFile) - this.allScreen = File(screenFile); - console.log(allScreen); + this.allScreen = new File(screenFile); } + override onEvent(event: Int, path?: String): void { - + // 只监听文件新增事件 if (event == FileObserver.CREATE) { - let newPath: string = new File(allScreen, path!).path; + + let newPath: string = new File(this.allScreen, path!).path; let currentTime = System.currentTimeMillis(); if ((currentTime - lastFileObserverTime) < 1000) { @@ -41,32 +67,17 @@ class ScreenFileObserver extends FileObserver { return; } - console.log(path); lastFileObserverTime = System.currentTimeMillis() - listenOption.onImageCatchChange(newPath) + let ret = { + image:newPath + } + listenOption.onImageCatchChange(ret) } } } -/** - * android 10 版本使用的文件监听器 - */ -let screenOB: ScreenFileObserver | null = null; - -type onImageCatchOptions = { - onImageCatchChange: (res: string) => void; -}; - -let listenOption: onImageCatchOptions = new onImageCatchOptions(); - -let lastFileObserverTime: number = 0; - - - - - @@ -91,24 +102,20 @@ export function requestPremission() { /** * 开启截图监听 */ -export function onUserCaptureScreen(success: (res: string) => void) { - listenOption.onImageCatchChange = success; +export function onUserCaptureScreen(success: (res: any) => void) { + listenOption.onImageCatchChange = success; // android 10 以上版本,使用监听文件的方式,更加可靠 let directory_screenshot: File; - let directory_pictures = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES); - let directory_dcim = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM); - - console.log(directory_pictures); - console.log(directory_dcim); - + let directory_pictures = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES); + let directory_dcim = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM); if (Build.MANUFACTURER.equals("Xiaomi", true)) { - directory_screenshot = File(directory_dcim, "Screenshots"); + directory_screenshot = new File(directory_dcim, "Screenshots"); } else { - directory_screenshot = File(directory_pictures, "Screenshots"); + directory_screenshot = new File(directory_pictures, "Screenshots"); } if (screenOB != null) { @@ -117,13 +124,13 @@ export function onUserCaptureScreen(success: (res: string) => void) { screenOB = new ScreenFileObserver(directory_screenshot.path) screenOB!.startWatching() - } + /** * 关闭截屏监听 */ -export function offUserCaptureScreen(success: (res: string) => void) { +export function offUserCaptureScreen(success: (res: any) => void) { // android 10以上,关闭监听通过移除文件监听器实现 if (screenOB != null) { @@ -132,7 +139,10 @@ export function offUserCaptureScreen(success: (res: string) => void) { } lastFileObserverTime = 0; - success(""); + let ret = { + + } + success(ret); }