diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 0ed9e4030e3b73fda404365d3c982ddc82865838..bb929dbdd3e5ffc039c746bb01914635f7166ed4 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -22,7 +22,7 @@ import { promptAction } from '@kit.ArkUI'; struct Index { @State message: string = ''; @State content: string = ''; - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; private path = this.context.filesDir + '/text.txt'; build() { @@ -58,7 +58,12 @@ struct Index { .margin({ top: 12 }) .onClick(() => { fileNapi.write(this.path, this.message); - promptAction.showToast({ message: $r('app.string.written_successfully'), showMode: promptAction.ToastShowMode.DEFAULT }); + this.getUIContext() + .getPromptAction() + .showToast({ + message: $r('app.string.written_successfully'), + showMode: promptAction.ToastShowMode.DEFAULT + }); }) Text($r('app.string.read_data')) @@ -81,7 +86,8 @@ struct Index { .margin({ top: 12 }) .onClick(() => { this.content = fileNapi.read(this.path); - promptAction.showToast({ message: $r('app.string.read_successfully') }); + this.getUIContext() + .getPromptAction().showToast({ message: $r('app.string.read_successfully') }); }) } .padding({