From 5eb8e1f7908e78b8efcd22d0a1d68dc9f766de0d Mon Sep 17 00:00:00 2001 From: kuangning <2540487435@qq.com> Date: Thu, 8 May 2025 11:26:10 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Aapi=E5=8D=87=E7=BA=A7=E8=87=B316?= =?UTF-8?q?=EF=BC=8C=E5=BA=9F=E5=BC=83api=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 2 +- entry/src/main/ets/entryability/EntryAbility.ets | 1 + entry/src/main/ets/model/GetResourceString.ets | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index c033ce4..e8de1a3 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -5,7 +5,7 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", + "compatibleSdkVersion": "5.0.4(16)", "runtimeOS": "HarmonyOS", } ], diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index ba0058d..47d0604 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -33,6 +33,7 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('uiContext', uiContext); }); windowStage.loadContent('pages/Index', (err) => { + AppStorage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; diff --git a/entry/src/main/ets/model/GetResourceString.ets b/entry/src/main/ets/model/GetResourceString.ets index 45b7542..e2d38b6 100644 --- a/entry/src/main/ets/model/GetResourceString.ets +++ b/entry/src/main/ets/model/GetResourceString.ets @@ -13,7 +13,9 @@ * limitations under the License. */ +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); + export function getResourceString(resource: Resource, __this: object): string { - let resourceString = getContext(__this).resourceManager.getStringSync(resource.id); + let resourceString = uiContext?.getHostContext()!.resourceManager.getStringSync(resource.id)!; return resourceString; } \ No newline at end of file -- Gitee