一、跳转应用详情页
鸿蒙跳转应用详情页功能,使用场景可以是引导用户进入应用详情页授予应用权限。
TypeScript
gotoAppDetail(context:common.UIAbilityContext){
let bundleName = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).name
let wantInfo: Want = {
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: 'application_info_entry',
parameters: {
pushParams: bundleName // 打开指定应用的详情页面
}
}
context.startAbility(wantInfo)
}
二、如何获取 UIAbilityContext
1.在 UIAbility 中获取
TypeScript
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
// 获取UIAbility实例的上下文
let context = this.context;
}
}
2.在页面中获取
TypeScript
import common from '@ohos.app.ability.common';
import Want from '@ohos.app.ability.Want';
@Entry
@Component
struct Index {
private context = getContext(this) as common.UIAbilityContext;
// 页面展示
build() {
}
}