From ecc87a59966d84575153a34bb400a05b9b804abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E5=8D=93=E4=BC=A6?= <2658469835@qq.com> Date: Thu, 8 May 2025 14:30:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3,=E5=8D=87=E7=BA=A7api(16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 17 +++++++++++++++-- .../src/main/ets/entryability/EntryAbility.ets | 1 + entry/src/main/ets/pages/Index.ets | 14 ++++++++------ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index 248da3f..33fb71d 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,13 +1,26 @@ { "app": { "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "C:\\Users\\Admin\\.ohos\\config\\default_image-compression_b84ao4kwQBRZ0zx0lGRk1JX0DBUTNmRH2FP8IWSxMFM=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001B3DD979DE6580FAF50AA69E679DB71C3EF5733767D266463E899E0020891FD551EFFB13258E0761", + "profile": "C:\\Users\\Admin\\.ohos\\config\\default_image-compression_b84ao4kwQBRZ0zx0lGRk1JX0DBUTNmRH2FP8IWSxMFM=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\Admin\\.ohos\\config\\default_image-compression_b84ao4kwQBRZ0zx0lGRk1JX0DBUTNmRH2FP8IWSxMFM=.p12", + "storePassword": "0000001BA14BED27D9F7E66ED5C602568F3C61BC16647FBE14FDE3AB4993B8DA30D112CE47CB6A9BA6323C" + } + } ], "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 217744d..65d64d6 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 0ae0794..f14114b 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 }); -- Gitee From 467d5139d97b5575708503262684ba500987fc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E5=8D=93=E4=BC=A6?= <2658469835@qq.com> Date: Fri, 23 May 2025 14:59:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E5=88=A0=E9=99=A4=E7=AD=BE=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index 33fb71d..651829e 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,20 +1,6 @@ { "app": { - "signingConfigs": [ - { - "name": "default", - "type": "HarmonyOS", - "material": { - "certpath": "C:\\Users\\Admin\\.ohos\\config\\default_image-compression_b84ao4kwQBRZ0zx0lGRk1JX0DBUTNmRH2FP8IWSxMFM=.cer", - "keyAlias": "debugKey", - "keyPassword": "0000001B3DD979DE6580FAF50AA69E679DB71C3EF5733767D266463E899E0020891FD551EFFB13258E0761", - "profile": "C:\\Users\\Admin\\.ohos\\config\\default_image-compression_b84ao4kwQBRZ0zx0lGRk1JX0DBUTNmRH2FP8IWSxMFM=.p7b", - "signAlg": "SHA256withECDSA", - "storeFile": "C:\\Users\\Admin\\.ohos\\config\\default_image-compression_b84ao4kwQBRZ0zx0lGRk1JX0DBUTNmRH2FP8IWSxMFM=.p12", - "storePassword": "0000001BA14BED27D9F7E66ED5C602568F3C61BC16647FBE14FDE3AB4993B8DA30D112CE47CB6A9BA6323C" - } - } - ], + "signingConfigs": [], "products": [ { "name": "default", -- Gitee