HarmonyOS 鸿蒙Next开发中,怎么拉起系统的浏览器,然后传递url?
HarmonyOS 鸿蒙Next开发中,怎么拉起系统的浏览器,然后传递url?
关于HarmonyOS 鸿蒙Next开发中,怎么拉起系统的浏览器,然后传递url?的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
可以试试下面的代码:
import common from '@ohos.app.ability.common';
import Want from ‘@ohos.app.ability.Want’;
import { BusinessError } from ‘@ohos.base’;
function startBrowsableAbility(context: common.UIAbilityContext): void {
let want: Want = {
action: ‘ohos.want.action.viewData’,
entities: [‘entity.system.browsable’],
uri: ‘https://www.huawei.com/’
};
context.startAbility(want)
.then(() => {
console.log(‘success’)
})
.catch((err: BusinessError) => {
console.error(Failed to startAbility. Code: ${err.code}, message: ${err.message}
);
});
}
struct BrowsePage {
@State message: string = ‘Hello World’;
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
startBrowsableAbility(context);
})
}
.width(‘100%’)
}
.height(‘100%’)
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>