从应用内跳转至外部浏览器,基于 Want 来实现,同时也可以通过其方式尝试跳转至其它系统模块,具体可参考如下 code :
方法调用
// 调用
pushOutsideWeb(controller, url)
方法实现
import { common, contextConstant, Want } from '@kit.AbilityKit';
import { HintMessage } from '../macros/IMedConfig';
export function pushOutsideWeb(abilityContext: common.UIAbilityContext, url: string) {
if (url) {
let context = getContext(abilityContext) as common.UIAbilityContext
let wantInfo: Want = {
action: 'ohos.want.action.viewData',
entities: ['entity.system.browsable'],
uri: url
}
context.startAbility(wantInfo).then(() => {
console.log('[跳转至外部浏览器] - success')
}).catch((err: BusinessError) => {
console.error('[跳转至外部浏览器] - Failed to startAbility. Code: ' + err.code + 'message:' + err.message);
})
} else {
showToast(HintMessage.HintURLEmpty)
}
}
以上便是此次分享的全部内容,希望能对大家有所帮助!