diff --git a/build-profile.json5 b/build-profile.json5 index 248da3f29a6fc67f61fa83f56e1f454d0c93b78c..651829e3213b5de16149c9db23ceb3e01533aab7 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,13 +1,12 @@ { "app": { - "signingConfigs": [ - ], + "signingConfigs": [], "products": [ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.2(14)", - "runtimeOS": "HarmonyOS", + "compatibleSdkVersion": "5.0.4(16)", + "runtimeOS": "HarmonyOS" } ], "buildModeSet": [ diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 217744d8eb6d893e1138cd660209ce4d0441ac4f..65d64d6985a9f1376797cbb136007dd2d26aef73 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -31,6 +31,7 @@ export default class EntryAbility extends UIAbility { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 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/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 0ae0794c1539ec6ee7da6f3d42bc508417693ef4..f14114bfed5242a017da847472c02a1be7d50cc0 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -89,8 +89,10 @@ async function packingImage(compressedImageData: ArrayBuffer, sourcePixelMap: im return compressedImageData; } +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); + async function saveImage(compressedImageData: ArrayBuffer): Promise { - const context: Context = getContext(); + const context: Context = uiContext!.getHostContext()!; const compressedImageUri: string = context.filesDir + '/' + 'afterCompression.jpeg'; try { const res = fileIo.accessSync(compressedImageUri); @@ -118,10 +120,10 @@ struct Index { private sourceImageByteLength: number = 0; private compressedByteLength: number = 0; private maxCompressedImageSize: number = 0; - private context: Context = getContext(this); + private context: Context = this.getUIContext().getHostContext()!; aboutToAppear(): void { - const context: Context = getContext(this); + const context: Context = this.getUIContext().getHostContext()!; const resourceMgr: resourceManager.ResourceManager = context.resourceManager; resourceMgr.getRawFileContent('beforeCompression.jpeg').then((fileData: Uint8Array) => { const buffer = fileData.buffer.slice(0); @@ -170,7 +172,7 @@ struct Index { Button($r('app.string.image_compression')).onClick(() => { if (this.maxCompressedImageSize === 0) { - AlertDialog.show({ + this.getUIContext().showAlertDialog({ message: $r('app.string.prompt_enter_value_greater_than_0'), alignment: DialogAlignment.Center }); @@ -178,12 +180,12 @@ struct Index { } if (this.maxCompressedImageSize * CommonConstants.BYTE_CONVERSION > this.sourceImageByteLength) { if (this.sourceImageByteLength === 0) { - AlertDialog.show({ + this.getUIContext().showAlertDialog({ message: $r('app.string.image_get_failed'), alignment: DialogAlignment.Center }); } else { - AlertDialog.show({ + this.getUIContext().showAlertDialog({ message: $r('app.string.prompt_not_require_compression'), alignment: DialogAlignment.Center });