以打开浏览器为例,假设设备上安装了一个或多个浏览器应用。为了使浏览器应用能够正常工作,需要在 module.json5配置文件 进行配置,具体配置如下:

{
  "module": {
    ...
    "abilities": [
      {
        ...
        "skills": [
          {
            "entities": [
              "entity.system.home",
              "entity.system.browsable"
              ...
            ],
            "actions": [
              "action.system.home",
              "ohos.want.action.viewData"
              ...
            ],
            "uris": [
              {
                "scheme": "https",
                "host": "www.test.com",
                "port": "8080",
                // prefix matching
                "pathStartWith": "query"
              },
              {
                "scheme": "http",
                ...
              }
              ...
            ]
          }
        ]
      }
    ]
  }
}

在调用方UIAbility中,使用隐式Want方式启动浏览器应用。

import common from '@ohos.app.ability.common';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';

let context = getContext(this) as common.UIAbilityContext;
let wantInfo: Want = {
  // uncomment line below if wish to implicitly query only in the specific bundle.
  // bundleName: 'com.example.myapplication',
  action: 'ohos.want.action.viewData',
  // entities can be omitted.
  entities: ['entity.system.browsable'],
  uri: 'https://www.test.com:8080/query/student'
}
context.startAbility(wantInfo).then(() => {
  // ...
}).catch((err: BusinessError) => {
  // ...
})

匹配过程分析:

  1. 调用方传入的want参数的action不为空,待匹配目标应用组件的skills配置中的actions不为空且包含调用方传入的want参数的action,action匹配成功。
  2. 调用方传入的want参数的entities不为空,待匹配目标应用组件的skills配置中的entities不为空且包含调用方传入的want参数的entities,entities匹配成功。
  3. 待匹配目标应用组件的skills配置中内uris拼接为https://www.test.com:8080/query*(其中*表示通配符),包含调用方传入的want参数的uri,uri匹配成功。

当存在多个匹配的应用时,系统将弹出应用选择框供用户选择。示意效果如下图所示。

为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05

《鸿蒙开发学习手册》:

如何快速入门:https://qr21.cn/FV7h05

  1. 基本概念
  2. 构建第一个ArkTS应用
  3. ……

开发基础知识:https://qr21.cn/FV7h05

  1. 应用基础知识
  2. 配置文件
  3. 应用数据管理
  4. 应用安全管理
  5. 应用隐私保护
  6. 三方应用调用管控机制
  7. 资源分类与访问
  8. 学习ArkTS语言
  9. ……

基于ArkTS 开发:https://qr21.cn/FV7h05

  1. Ability开发
  2. UI开发
  3. 公共事件与通知
  4. 窗口管理
  5. 媒体
  6. 安全
  7. 网络与链接
  8. 电话服务
  9. 数据管理
  10. 后台任务(Background Task)管理
  11. 设备管理
  12. 设备使用信息统计
  13. DFX
  14. 国际化开发
  15. 折叠屏系列
  16. ……

鸿蒙开发面试真题(含参考答案):https://qr18.cn/F781PH

鸿蒙开发面试大盘集篇(共计319页):https://qr18.cn/F781PH

1.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐