HarmonyOS 鸿蒙Next:为什么startAbility首次跳转UiAbility成功,后续跳转失败并返回错误码201,错误信息为“The application does not have permission to call the interface”
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))
})
更多关于HarmonyOS 鸿蒙Next:为什么startAbility首次跳转UiAbility成功,后续跳转失败并返回错误码201,错误信息为“The application does not have permission to call the interface”的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
我也遇到相同的问题,求处理办法
**exported 之前也试过,没什么用**
![图像]
![图像]
在TestAbility添加上**“exported”: true** 标识当前ExtensionAbility组件是否可以被其他应用调用。
{
"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",
"exported": true
}
没有权限的话,不应该一次都跳转不成功吗
该配置的都配置了,还是那样,跳转几次就报错了
我是快捷键创建的第二个UIAbility页面的,按理来讲module.json5里面的数据会自动创建好的,不可能创建出来就缺胳膊断腿的
跳转完,就出来两个,(虽然后面跳转不过去了,但是还是能点击进去第二个页面)
HarmonyOS 鸿蒙Next系统中,startAbility
方法首次跳转UiAbility
成功,但后续跳转失败并返回错误码201,错误信息提示“The application does not have permission to call the interface”,通常意味着应用在尝试调用某个接口时没有相应的权限。
这种情况可能由以下原因造成:
-
权限未声明:检查应用的
config.json
文件,确保已经正确声明了所需权限。对于UiAbility
的调用,可能需要特定的系统权限或应用间通信权限。 -
权限未被授予:即使
config.json
中声明了权限,用户也可能在系统设置中未授予这些权限。检查系统设置,确保应用拥有所有必需的权限。 -
权限动态管理:鸿蒙系统可能引入了更细粒度的权限管理,某些操作可能在运行时需要动态请求权限。检查代码中是否有遗漏的动态权限请求逻辑。
-
Ability间通信问题:如果错误发生在Ability间通信,检查发送和接收Ability的配置,确保它们正确配置且能相互通信。
-
系统Bug或限制:系统本身可能存在Bug或特定版本的限制,导致权限管理异常。
如果问题依旧没法解决请联系官网客服,官网地址是 https://www.itying.com/category-93-b0.html