HarmonyOS 鸿蒙Next:为什么startAbility首次跳转UiAbility成功,后续跳转失败并返回错误码201,错误信息为“The application does not have permission to call the interface”
module.json5代码
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"phone",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"requestPermissions": [
{
"name": "ohos.permission.READ_MEDIA",
"reason": "$string:permission_storage",
"usedScene": {
"abilities": [
"EntryAbility"
]
}
},
{
"name": "ohos.permission.WRITE_MEDIA",
"reason": "$string:permission_storage",
"usedScene": {
"abilities": [
"EntryAbility"
]
}
}
],
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
},
{
"name": "TestAbility",
"srcEntry": "./ets/entryability/TestAbility.ts",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:AssortedAbility1_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
}
]
}
}
跳转代码:
context = getContext(this) as common.UIAbilityContext
let want = {
deviceId: "",
'bundleName': this.context.abilityInfo.bundleName,
'abilityName': 'TestAbility',
'moduleName': ''
};
this.context.startAbility(want).then(() => {
console.log(`页面跳转成功`)
}).catch((err) => {
console.log(`页面跳转错误 message: ${JSON.stringify(err.message)}`+' code: '+JSON.stringify(err.code))
})