From a228142a9bafabf687bea9205c31362acbb93af5 Mon Sep 17 00:00:00 2001 From: lewis Date: Sun, 14 Sep 2025 11:34:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20IDE=E5=91=8A=E8=AD=A6=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 33 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 9401ceb..fd1dd1e 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -15,6 +15,7 @@ import { webview } from '@kit.ArkWeb'; import { common, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { distributedDeviceManager } from '@kit.DistributedServiceKit'; import { OriginPage } from './OriginPage'; @@ -43,12 +44,17 @@ struct Index { let dmInstance: distributedDeviceManager.DeviceManager = distributedDeviceManager.createDeviceManager(this.bundleName); if (typeof dmInstance === 'object' && dmInstance !== null) { - let list = dmInstance.getAvailableDeviceListSync(); - if (typeof (list) === 'undefined' || typeof (list.length) === 'undefined') { - Logger.info('EntryAbility onButtonClick getRemoteDeviceId err: list is null') - return networkIdRet; + try { + let list = dmInstance.getAvailableDeviceListSync(); + if (typeof (list) === 'undefined' || typeof (list.length) === 'undefined') { + Logger.info('EntryAbility onButtonClick getRemoteDeviceId err: list is null') + return networkIdRet; + } + networkIdRet = list[0].networkId; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Execution failed, code = %{public}d, message = %{public}s', + error.code, error.message); } - networkIdRet = list[0].networkId; } else { Logger.error('EntryAbility onButtonClick getRemoteDeviceId err: dmClass is null'); } @@ -56,9 +62,14 @@ struct Index { } onBackPress(): boolean | void { - if (this.controller.accessBackward()) { - this.controller.backward(); - return true; + try { + if (this.controller.accessBackward()) { + this.controller.backward(); + return true; + } + } catch (error) { + hilog.error(0x0000, 'testTag', 'Execution failed, code = %{public}d, message = %{public}s', + error.code, error.message); } } @@ -92,7 +103,11 @@ struct Index { }); }); this.functionsMap.set('appgallery://pages/toMarketDetailPage', () => { - this.context.openLink('https://appgallery.huawei.com/app/detail?id=com.huawei.hmsapp.appgallery'); + this.context.openLink('https://appgallery.huawei.com/app/detail?id=com.huawei.hmsapp.appgallery') + .catch((error: BusinessError) => { + hilog.error(0x0000, 'testTag', 'Execution failed, code = %{public}d, message = %{public}s', + error.code, error.message); + }); }); this.functionsMap.set('cross-device://pages/crossDevice', () => { try { -- Gitee From d7e5f623122c7f30f51b2ec4ed81de65fd510237 Mon Sep 17 00:00:00 2001 From: lewis Date: Mon, 22 Sep 2025 11:06:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Navigation.ets | 21 -------- entry/src/main/ets/pages/Navigation1.ets | 35 ------------- entry/src/main/ets/pages/Navigation2.ets | 52 -------------------- entry/src/main/ets/pages/Navigation3.ets | 62 ------------------------ entry/src/main/ets/pages/Navigation4.ets | 53 -------------------- entry/src/main/ets/pages/OriginPage.ets | 4 -- 6 files changed, 227 deletions(-) delete mode 100644 entry/src/main/ets/pages/Navigation.ets delete mode 100644 entry/src/main/ets/pages/Navigation1.ets delete mode 100644 entry/src/main/ets/pages/Navigation2.ets delete mode 100644 entry/src/main/ets/pages/Navigation3.ets delete mode 100644 entry/src/main/ets/pages/Navigation4.ets diff --git a/entry/src/main/ets/pages/Navigation.ets b/entry/src/main/ets/pages/Navigation.ets deleted file mode 100644 index 805e170..0000000 --- a/entry/src/main/ets/pages/Navigation.ets +++ /dev/null @@ -1,21 +0,0 @@ -@Component -export struct Navigation1 { - @Consume('navPathStack') navPathStack: NavPathStack; - - build() { - // [Start navigation] - NavDestination() { - Column() { - Button($r('app.string.back_to_web_page')) - .width('100%') - .height(40) - .onClick(() => { - this.navPathStack.pushPath({ name: 'WebPage' }); - }) - } - // ... - } - .title('ArkTS页面') - // [End navigation] - } -} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Navigation1.ets b/entry/src/main/ets/pages/Navigation1.ets deleted file mode 100644 index 6cb1651..0000000 --- a/entry/src/main/ets/pages/Navigation1.ets +++ /dev/null @@ -1,35 +0,0 @@ -import { webview } from "@kit.ArkWeb"; - -class PathStack{ - pop(){ - return - } -} -@Component -export struct Navigation2 { - @Consume('navPathStack') navPathStack: NavPathStack; - private controller: WebviewController = new webview.WebviewController; - - build() { - // [Start navigation1] - NavDestination() { - Column() { - Web({ - src: $rawfile('index.html'), - controller: this.controller - }) - .zoomAccess(false) - .onLoadIntercept((event) => { - const url: string = event.data.getRequestUrl(); - if (url === 'arkts://pages/toOriginPage') { - this.navPathStack.pop(); - } - // [StartExclude navigation1] - return false; - // [EndExclude navigation1] - }) - } - } - // [End navigation1] - } -} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Navigation2.ets b/entry/src/main/ets/pages/Navigation2.ets deleted file mode 100644 index 9b12d09..0000000 --- a/entry/src/main/ets/pages/Navigation2.ets +++ /dev/null @@ -1,52 +0,0 @@ -import { bundleManager, common, OpenLinkOptions } from "@kit.AbilityKit"; -import { BusinessError } from "@kit.BasicServicesKit"; -import { webview } from "@kit.ArkWeb"; - -// [Start link1] -const link: string = "appScheme://www.test.com:80/path1"; -// [End link1] -@Component -export struct Navigation3 { - @Consume('navPathStack') navPathStack: NavPathStack; - private controller: WebviewController = new webview.WebviewController; - private context = this.getUIContext().getHostContext() as common.UIAbilityContext; - - build() { - // [Start link3] - Navigation(this.navPathStack) { - Column() { - Web({ - src: $rawfile('index.html'), - controller: this.controller - }) - .zoomAccess(false) - .onLoadIntercept((event) => { - const url: string = event.data.getRequestUrl(); - if (url === 'third-party://pages/toThirdApp') { - const link: string = "appScheme://www.test.com:80/path1"; - // [Start link2] - if (!bundleManager.canOpenLink(link)) { - return true; - } - // [End link2] - // Configuration parameter. - const openLinkOptions: OpenLinkOptions = { - appLinkingOnly: false, - parameters: { - name: 'test' - } - }; - // Open the application using the openLink interface. - this.context.openLink(link, openLinkOptions).then(() => { - console.info('open link success.'); - }).catch((err: BusinessError) => { - console.error(`open link failed. Code is ${err.code}, message is ${err.message}`); - }) - } - return url !== 'resource://rawfile/index2.html'; - }) - } - } - // [End link3] - } -} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Navigation3.ets b/entry/src/main/ets/pages/Navigation3.ets deleted file mode 100644 index 4f47e78..0000000 --- a/entry/src/main/ets/pages/Navigation3.ets +++ /dev/null @@ -1,62 +0,0 @@ -import { hilog } from "@kit.PerformanceAnalysisKit"; -import { common } from "@kit.AbilityKit"; -import { webview } from "@kit.ArkWeb"; - -class context{ - startAbilityByType(name:string,a:ESObject,b:ESObject){ - return - } -} -@Component -export struct Navigation4 { - @Consume('navPathStack') navPathStack: NavPathStack; - private controller: WebviewController = new webview.WebviewController; - private context = this.getUIContext().getHostContext() as common.UIAbilityContext; - - build() { - // [Start path_stack1] - Navigation(this.navPathStack) { - Column() { - Web({ - src: $rawfile('index.html'), - controller: this.controller - }) - .zoomAccess(false) - .onLoadIntercept((event) => { - const url: string = event.data.getRequestUrl(); - if (url === 'arkts://pullSpeciallyApp') { - const wantParam: Record = { - 'sceneType': 1, - 'destinationLatitude': 32.060844, - 'destinationLongitude': 118.78315, - 'destinationName': 'xx市xx路xx号', - 'destinationPoiIds': { - 1: '111111111111', - 2: '222222222222' - } as Record, - 'originName': 'xx市xx公园', - 'originLatitude': 31.060844, - 'originLongitude': 120.78315, - 'originPoiIds': { - 1: '333333333333', - 2: '444444444444' - } as Record, - 'vehicleType': 0 - }; - const abilityStartCallback: common.AbilityStartCallback = { - onError: (code: number, name: string, message: string) => { - hilog.error(0x0000, 'Sample', '%{public}s', 'onError code ' + code + 'name: ' + name + 'message: ' + message); - }, - onResult: (result:ESObject) => { - hilog.error(0x0000, 'Sample', '%{public}s', 'onResult result: ' + JSON.stringify(result)); - } - }; - this.context.startAbilityByType('navigation', wantParam, abilityStartCallback); - } - return url !== 'resource://rawfile/index.html'; - }) - } - } - // [End path_stack1] - } -} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Navigation4.ets b/entry/src/main/ets/pages/Navigation4.ets deleted file mode 100644 index a375cce..0000000 --- a/entry/src/main/ets/pages/Navigation4.ets +++ /dev/null @@ -1,53 +0,0 @@ -import { photoAccessHelper } from "@kit.MediaLibraryKit"; -import { BusinessError } from "@kit.BasicServicesKit"; -import { webview } from "@kit.ArkWeb"; -import { Constants } from "../common/Constants"; -import { OriginPage } from "./OriginPage"; - -@Component -export struct Navigation5 { - @Consume('navPathStack') navPathStack: NavPathStack; - private controller: WebviewController = new webview.WebviewController; - - @Builder - PageMap(name: string) { - if (name === Constants.ORIGIN_PAGE) { - OriginPage() - } - } - - build() { - // [Start path_stack2] - Navigation(this.navPathStack) { - Column() { - Web({ - src: $rawfile('index.html'), - controller: this.controller - }) - .zoomAccess(false) - .onLoadIntercept((event) => { - const url: string = event.data.getRequestUrl(); - if (url === 'photo://pages/selectPhoto') { - const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); - photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // Filter and select the media file type as IMAGE - photoSelectOptions.maxSelectNumber = 5; // Select the maximum number of media files - let uris: Array = []; - const photoViewPicker = new photoAccessHelper.PhotoViewPicker(); - photoViewPicker.select(photoSelectOptions) - .then((photoSelectResult: photoAccessHelper.PhotoSelectResult) => { - uris = photoSelectResult.photoUris; - console.info('photoViewPicker.select to file succeed and uris are:' + uris); - }) - .catch((err: BusinessError) => { - console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`); - }) - } - return url !== 'resource://rawfile/index3.html'; - }) - } - } - .hideTitleBar(true) - .navDestination(this.PageMap) - // [End path_stack2] - } -} \ No newline at end of file diff --git a/entry/src/main/ets/pages/OriginPage.ets b/entry/src/main/ets/pages/OriginPage.ets index 187c4e4..c517f10 100644 --- a/entry/src/main/ets/pages/OriginPage.ets +++ b/entry/src/main/ets/pages/OriginPage.ets @@ -21,7 +21,6 @@ export struct OriginPage { @StorageProp(Constants.SYSTEM_LANGUAGE_KEY) la: string = ''; build() { - // [Start nav_dest] NavDestination() { Column() { Button('return to the web page') @@ -31,7 +30,6 @@ export struct OriginPage { this.navPathStack.pop(); }) } - // [StartExclude nav_dest] .width(Constants.FULL_SCREEN) .height(Constants.FULL_SCREEN) .justifyContent(FlexAlign.End) @@ -41,8 +39,6 @@ export struct OriginPage { bottom: $r('app.float.space_bottom') }) } - // [EndExclude nav_dest] .title(this.la = 'en-Latn-CN' ? 'OriginPage' : 'NativePage') - // [End nav_dest] } } \ No newline at end of file -- Gitee