使用隱式Want打開網(wǎng)址
以打開瀏覽器為例,假設(shè)設(shè)備上安裝了一個(gè)或多個(gè)瀏覽器應(yīng)用。為了使瀏覽器應(yīng)用能夠正常工作,需要在[module.json5配置文件]進(jìn)行配置,具體配置如下: 開發(fā)前請熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
{
"module": {
"abilities": [
{
// 入口配置
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
},
// 瀏覽器配置
{
"actions": [
"ohos.want.action.viewData"
],
"entities": [
"entity.system.browsable"
],
"uris": [{
"scheme": "https",
"host": "www.test.com",
"port": "8080",
"pathStartWith": "query"
},
{
"scheme": "http"
}
]
}
]
}
]
}
}
在調(diào)用方UIAbility中,使用隱式Want方式啟動瀏覽器應(yīng)用。
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) = > {
// ...
})
匹配過程分析:
- 調(diào)用方傳入的want參數(shù)的action不為空,待匹配目標(biāo)應(yīng)用組件的skills配置中的actions不為空且包含調(diào)用方傳入的want參數(shù)的action,action匹配成功。
- 調(diào)用方傳入的want參數(shù)的entities不為空,待匹配目標(biāo)應(yīng)用組件的skills配置中的entities不為空且包含調(diào)用方傳入的want參數(shù)的entities,entities匹配成功。
- 待匹配目標(biāo)應(yīng)用組件的skills配置中內(nèi)uris拼接為
https://www.test.com:8080/query*
(其中*表示通配符),包含調(diào)用方傳入的want參數(shù)的uri,uri匹配成功。
當(dāng)存在多個(gè)匹配的應(yīng)用時(shí),系統(tǒng)將彈出應(yīng)用選擇框供用戶選擇。示意效果如下圖所示。
審核編輯 黃宇
-
框架
+關(guān)注
關(guān)注
0文章
404瀏覽量
17740 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2469瀏覽量
43652
發(fā)布評論請先 登錄
相關(guān)推薦
鴻蒙Ability Kit(程序框架服務(wù))【ServiceExtensionAbility】

鴻蒙Ability開發(fā)-Stage模型下Ability的創(chuàng)建和使用
HarmonyOS NEXT應(yīng)用元服務(wù)開發(fā)Intents Kit(意圖框架服務(wù))綜述
跟阿斌一起學(xué)鴻蒙(2): Ability vs App?
跟阿斌一起學(xué)鴻蒙(2): Ability vs App?
HarmonyOS/OpenHarmony應(yīng)用開發(fā)-信息傳遞載體Want使用
HarmonyOS/OpenHarmony應(yīng)用開發(fā)-stage使用隱示Want打開網(wǎng)址
鴻蒙應(yīng)用模型:【Ability Kit】簡介

鴻蒙Ability Kit(程序框架服務(wù))【Ability內(nèi)頁面間的跳轉(zhuǎn)】

鴻蒙Ability Kit(程序框架服務(wù))【Ability與ServiceExtensionAbility通信】

鴻蒙Ability Kit(程序框架服務(wù))【顯式Want與隱式Want匹配規(guī)則】

鴻蒙Ability Kit(程序框架服務(wù))【應(yīng)用間使用Want分享數(shù)據(jù)】

評論