HarmonyOS鸿蒙Next中应用点击跳转浏览器访问指定地址
HarmonyOS鸿蒙Next中应用点击跳转浏览器访问指定地址
3 回复
使用隐式Want打开网址
参考文档
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/explicit-implicit-want-mappings-V5
更多关于HarmonyOS鸿蒙Next中应用点击跳转浏览器访问指定地址的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
let want: Want = {
action: 'ohos.want.action.viewData',
entities: ['entity.system.browsable'],
uri: 'https://www.huawei.com'
};
在HarmonyOS鸿蒙Next中,应用可以通过Intent
实现点击跳转到浏览器访问指定地址。首先,创建一个Intent
对象,并设置其Action
为Intent.ACTION_VIEW
,然后使用Intent.setData()
方法指定目标URL。最后,调用startAbility(intent)
启动浏览器应用。代码示例如下:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.example.com"));
startAbility(intent);
这样可以实现从应用内跳转到浏览器访问指定URL。