OpenHarmony开发者论坛

标题: 开源鸿蒙如何才能拉起系统浏览器? [打印本页]

作者: 润开鸿_坚果    时间: 7 天前
标题: OpenHarmony如何才能拉起系统浏览器?
[md]OpenHarmony如何才能拉起系统浏览器?

![image-20250108134327152](https://luckly007.oss-cn-beijing ... 250108134327152.png)

## 通过隐式指定want参数中的action为ohos.want.action.viewData来拉起浏览器应用

**开发者可以通过隐式指定want参数中的action为ohos.want.action.viewData来拉起浏览器应用,并在want参数中的uri配置拉起后打开的网页链接。具体可参考如下代码。**

## 示例代码

```
import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

function startBrowsableAbility(context: common.UIAbilityContext): void {
 let want: Want = {
   action: 'ohos.want.action.viewData',
   entities: ['entity.system.browsable'],
   uri: 'https://www.nutpi.net/'
  };
 context.startAbility(want)
   .then(() => {
     console.error('Start browsableAbility successfully.');
   })
   .catch((err: BusinessError) => {
     console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
   });
}

@Entry
@Component
struct BrowsablePage {
 @State message: string = '拉起浏览器并打开坚果派官网';

 build() {
   Row() {
     Column() {
       Button(this.message)
         .fontSize(24)
         .fontWeight(FontWeight.Bold)
         .onClick(() => {
           const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
           startBrowsableAbility(context);
         })
     }
     .width('100%')
   }
   .height('100%')
  }
}
```

![image-20250108135018305](https://luckly007.oss-cn-beijing ... 250108135018305.png)

**如果大家开发遇到技术问题,可以在坚果派获取帮助,新书上市,也感谢大家多多支持。。**

## 《极速探索HarmonyOS NEXT:纯血OpenHarmony应用开发实践》

**订购链接:**[https://item.jd.com/101346041311 ... QCAorsmpIsapEaN-NPe\_RLJ5a5H3joUzhUGWV](https://item.jd.com/101346041311 ... e_RLJ5a5H3joUzhUGWV)
[/md]




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5