diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 514a651254d72e6319186cfa9b1207df59fd2f6c..b242da70264d2d7ded0e8e1e807aba4649e18266 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -75,11 +75,11 @@ struct Index { Button($r('app.string.native_so_add')) .customButtonStyle() .onClick(() => { - let content = getContext(this).resourceManager.getStringSync($r('app.string.native_so_content')); + let content = this.getUIContext().getHostContext()!.resourceManager.getStringSync($r('app.string.native_so_content')); // Integrate the SO library on the Native side directly to complete the addition operation let result = testNapi.nativeAdd(Number(this.paramX), Number(this.paramY)); if (this.paramX === '' || this.paramY === '') { - this.customToast(getContext(this).resourceManager.getStringSync($r('app.string.input_alert'))); + this.customToast(this.getUIContext().getHostContext()!.resourceManager.getStringSync($r('app.string.input_alert'))); } else { this.customToast(`${content}${result.toString()}`); } @@ -87,14 +87,14 @@ struct Index { Button($r('app.string.native_so_dlopen_sub')) .customButtonStyle() .onClick(() => { - let content = getContext(this).resourceManager.getStringSync($r('app.string.native_so_dlopen_content')); - let projectPath = getContext(this).bundleCodeDir; // Get the project path + let content = this.getUIContext().getHostContext()!.resourceManager.getStringSync($r('app.string.native_so_dlopen_content')); + let projectPath = this.getUIContext().getHostContext()!.bundleCodeDir; // Get the project path let abiPath = deviceInfo.abiList === 'x86_64' ? 'x86_64' : 'arm64'; let soLibPath = `${projectPath}/libs/${abiPath}/libnativeSub.so`; // Integrate the SO library on the Native side by dlopen to complete the subtraction operation let result = testNapi.nativeSub(Number(this.paramX), Number(this.paramY), soLibPath) if (this.paramX === '' || this.paramY === '') { - this.customToast(getContext(this).resourceManager.getStringSync($r('app.string.input_alert'))); + this.customToast(this.getUIContext().getHostContext()!.resourceManager.getStringSync($r('app.string.input_alert'))); } else { this.customToast(`${content}${result.toString()}`); } @@ -102,11 +102,11 @@ struct Index { Button($r('app.string.arkts_so_multiply')) .customButtonStyle() .onClick(() => { - let content = getContext(this).resourceManager.getStringSync($r('app.string.arkts_so_content')); + let content = this.getUIContext().getHostContext()!.resourceManager.getStringSync($r('app.string.arkts_so_content')); // Integrate the SO library that has been adapted to Native On the ArkTS side to complete the multiplication operation let result = multiplyNapi.multiply(Number(this.paramX), Number(this.paramY)); if (this.paramX === '' || this.paramY === '') { - this.customToast(getContext(this).resourceManager.getStringSync($r('app.string.input_alert'))); + this.customToast(this.getUIContext().getHostContext()!.resourceManager.getStringSync($r('app.string.input_alert'))); } else { this.customToast(`${content}${result.toString()}`); }