前提条件
设备上安装了一个或多个浏览器。
1.创建stage项目
2.新建一个Ability,名称为LlqAbility
3.新建一个page页,并与新建的LlqAbility绑定
4.浏览器应用中通过module.json5配置如下:
5.实现代码:
import context from '@ohos.application.context';
@Entry
@Component
struct Llq {
@State btn: string = '打开'
build() {
Row() {
Column() {
Button(this.btn)
.onClick(this.implicitStartAbility)
}
.width('100%')
}
.height('100%')
}
async implicitStartAbility() {
try {
let want = {
"action": "ohos.want.action.viewData",
"entities": [ "entity.system.browsable" ],
"uri": "https://www.test.com:8080/query/student",
"type": "text/plain"
}
let context = getContext(this) as context.AbilityContext;
await context.startAbility(want)
console.info(`explicit start ability succeed + 成功`)
} catch (error) {
console.info(`explicit start ability failed (失败) with ${error.code}`)
}
}
}
6.实现效果
点击按钮