# PullOtherApp **Repository Path**: FBFBFB/pull-other-app ## Basic Information - **Project Name**: PullOtherApp - **Description**: 【鸿蒙 Harmony Next 示例 代码】跳转短信、浏览器、设置、相机、拨号、应用市场等系统应用和已知bundlename、abilityname的三方应用。 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-02 - **Last Updated**: 2025-06-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 应用间跳转 ## 介绍 本示例介绍了应用跳转的多个场景案例。 1. 跳转短信、浏览器、设置、相机、拨号、应用市场等系统应用和已知bundlename、abilityname的三方应用。 1. 跳转相机拍照后返回照片展示。 1. 跳转三方应用,模拟简易支付。 1. 跳转web页,拉起相机和三方应用。 ## 效果预览 ![输入图片说明](screenshots/%E8%B7%B3%E8%BD%AC%E4%B8%89%E6%96%B9%E7%B3%BB%E7%BB%9F%E5%BA%94%E7%94%A8.gif) ## 约束与限制 1. 本示例仅支持标准系统上运行,支持设备:华为手机。 2. 手机ROM版本高于:NOH-AN00 204.1.0.72(SP2DEVC00E72R1P1) 3. IDE高于等于:DevEco Studio 5.0.0 4. SDK高于等于:HarmoneyOS NEXT Developer Preview2 B.0.72(API 12) ## 使用说明 打开应用,展示一列按钮,点击不同按钮会进行不同应用的跳转。有些跳转需要权限,每次跳转前会弹窗提示。 ## 实现思路 ### 点击跳转系统相机应用 1. 构造startAbility()函数,用于启动一个特定的能力(ability)。构建一个Want对象,包含要执行的操作(action)和参数(parameters),其中参数包括调用应用的Bundle名称(callBundleName)和是否支持多模式(supportMultiMode)。尝试使用this.context.startAbilityForResult启动能力,并在回调中处理结果。如果启动过程中出现错误(err.code 存在),记录错误日志并返回。如果启动成功,从结果中获取资源URI(uri),记录成功日志,并根据uri是否存在执行不同操作:若uri存在,调用this.save2Local方法保存到本地;若uri不存在,显示 “拍摄失败” 的提示。 ```typescript startAbility(action: string, bundleName: string) { let want: Want = { action: action, parameters: { // 拍照完成后返回的应用BundleName callBundleName: bundleName, supportMultiMode: false } }; try { this.context.startAbilityForResult(want, (err: BusinessError, result: common.AbilityResult) => { if (err.code) { // 处理业务逻辑错误 hilog.error(0x0000, 'startAbilityForResult failed', `${err.code}${err.message}`); return; } let uri: string = result?.want?.parameters?.resourceUri as string; // 执行正常业务 hilog.info(0x0000, 'Succeeded in starting ability for result', `${JSON.stringify(result)}${uri}`); if (uri) { // 保存到本地 this.save2Local(uri); } else { promptAction.showToast({ message: '拍摄失败' }) } }); } } ``` 2. 构造save2Local()函数,将通过uri标识的文件保存到本地沙箱目录。 ```typescript save2Local(uri: string) { try { let file = fileIo.openSync(uri, fileIo.OpenMode.READ_ONLY); let prefix = uri.substring(uri.lastIndexOf('.') + 1); let tempFileName = getContext(this).filesDir + '/' + new Date().getTime() + '.' + prefix; let tempFile = fileIo.openSync(tempFileName, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); fileIo.copyFileSync(file.fd, tempFile.fd); this.path = fileUri.getUriFromPath(tempFileName); this.isVideo = (prefix == 'mp4' || prefix == 'MP4'); hilog.info(0x0000, 'resolve2Sandbox successful.', ''); promptAction.showToast({ message: '拍摄成功' }) } } ``` ### 点击跳转Web应用 构造jumpTestApp()函数,启动一个特定的应用(通过bundleName和abilityName指定),并向其传递参数(parameters中的 message)。该函数返回一个Promise,在启动应用成功并获取到结果后,解析并返回结果中的 result 值;如果启动过程中出现错误,记录错误日志并返回 'failed'。 ```typescript async jumpTestApp(): Promise { let wantInfo: Want = { deviceId: '', bundleName: 'com.example.test1', abilityName: 'EntryAbility', parameters: { message: '待支付¥100' } } return this.context.startAbilityForResult(wantInfo).then((abilityResult) => { return abilityResult.want!.parameters!.result.toString(); }) } ``` ## 工程目录 ``` ├──entry // 入口模块 │ ├──build-profile.json5 // 编译配置文件,其中arkOptions需配置动态import依赖的包名 │ ├──oh-package.json5 // 依赖配置,需依赖全部子业务模块和RouterModule模块 │ ├──src/main/ets │ │ ├──components │ │ │ ├──JumpAppStore.ets // 跳转应用市场逻辑页 │ │ │ ├──JumpCamera.ets // 跳转相机逻辑页 │ │ │ └──JumpWeb.ets // 跳转web逻辑页 │ │ ├──entryability │ │ │ └──EntryAbility.ets │ │ ├──pages │ │ │ └──Index.ets // 首页 │ │ ├──utils // 工具类目录 │ │ │ └──SimpleAlertDialog.ets // 弹窗工具类 │ └──src/main/resources // 资源目录 │ └──rawfile │ └──index.html // web页 ``` ## 一份简单的问卷反馈 亲爱的Harmony Next开发者,您好!
为了协助您高效开发,提高鸿蒙场景化示例的质量,希望您在浏览或使用后抽空填写一份简单的问卷,我们将会收集您的宝贵意见进行优化:heart: [:arrow_right: **点击此处填写问卷** ](https://wj.qq.com/s2/19042938/95ab/)