From 155064a03a2d38d3d0d32f308ab06ff6e745447c Mon Sep 17 00:00:00 2001 From: WX1377357 Date: Tue, 13 May 2025 16:07:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=9F=E5=BC=83api=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 4fb607c..d56654d 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -25,8 +25,8 @@ import { FileNameList } from '../model/FileNameModel'; @Entry @Component struct Index { - private sandboxFilesDir: string = getContext(this).filesDir; - private resMgr: resourceManager.ResourceManager = getContext().resourceManager; + private sandboxFilesDir: string = this.getUIContext().getHostContext()!.filesDir; + private resMgr: resourceManager.ResourceManager = this.getUIContext().getHostContext()!.resourceManager; @Styles customButtonStyle() { @@ -56,7 +56,7 @@ struct Index { Button($r('app.string.button_sandbox')) .customButtonStyle() .onClick(() => { - let content = getContext(this).resourceManager + let content = this.getUIContext().getHostContext()!.resourceManager .getStringSync($r('app.string.file_content_sandbox')); FileAccess.transferSandboxPath(this.sandboxFilesDir, content); this.customToast(readFile(this.sandboxFilesDir + '/' + FileNameList[0])); @@ -65,7 +65,7 @@ struct Index { Button($r('app.string.button_splice')) .customButtonStyle() .onClick(() => { - let content = getContext(this).resourceManager + let content = this.getUIContext().getHostContext()!.resourceManager .getStringSync($r('app.string.file_content_splice')); FileAccess.splicePath(content); this.customToast(readFile(this.sandboxFilesDir + '/' + FileNameList[1])); @@ -81,13 +81,13 @@ struct Index { Button($r('app.string.button_create')) .customButtonStyle() .onClick(async () => { - CreateFileByPicker(getContext(this), FileNameList[3]); + CreateFileByPicker(this.getUIContext().getHostContext()!, FileNameList[3]); }) Button($r('app.string.button_write')) .customButtonStyle() .onClick(async () => { - let content = getContext(this).resourceManager + let content = this.getUIContext().getHostContext()!.resourceManager .getStringSync($r('app.string.file_content_picker')); await WriteFileByPicker(content).then((value: string) => { setTimeout(() => { -- Gitee