HarmonyOS鸿蒙Next中如何拉起系统浏览器,在线浏览隐私协议内容

HarmonyOS鸿蒙Next中如何拉起系统浏览器,在线浏览隐私协议内容 如何拉起系统浏览器,在线浏览隐私协议内容

4 回复
import common from '@ohos.app.ability.common';

function implicitStartAbility() {

  let context = getContext(this) as common.UIAbilityContext;

  let wantInfo = {
    
    // 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) => {
    
    // …
    
  })
}

更多关于HarmonyOS鸿蒙Next中如何拉起系统浏览器,在线浏览隐私协议内容的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


拉起浏览器的want是

let want: Want = {
    action: 'ohos.want.action.viewData',
    entities: ['entity.system.browsable'],
    uri: 'https://www.huawei.com'
};

然后调用want

const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
context.startAbility(want)

参考[https://blog.csdn.net/zhongcongxu01/article/details/142701842]

在HarmonyOS鸿蒙Next中,拉起系统浏览器并在线浏览隐私协议内容可以通过使用Intent来实现。具体步骤如下:

  1. 创建Intent对象:使用Intent类创建一个新的Intent对象,并设置其动作为Intent.ACTION_VIEW

  2. 设置URI:将隐私协议的URL作为URI传递给Intent对象。

  3. 启动浏览器:调用startAbility方法,将Intent对象传递给系统,系统会自动拉起默认浏览器并打开指定的URL。

示例代码如下:

import featureAbility from '@ohos.ability.featureAbility';

let intent = {
    action: 'action.view',
    uri: 'https://www.example.com/privacy-policy'
};

featureAbility.startAbility(intent)
    .then(() => {
        console.log('Browser launched successfully');
    })
    .catch((error) => {
        console.error('Failed to launch browser', error);
    });

这段代码会尝试拉起系统浏览器并打开指定的隐私协议URL。如果成功,控制台会输出Browser launched successfully;如果失败,会输出错误信息。

在HarmonyOS鸿蒙Next中,可以通过Intent拉起系统浏览器并打开指定URL。以下是一个示例代码:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.example.com/privacy-policy"));
startAbility(intent);

这段代码会启动系统浏览器并加载指定的隐私协议URL。确保在config.json中声明了ohos.permission.INTERNET权限。

回到顶部