HarmonyOS 鸿蒙Next scheme配置和跳转
HarmonyOS 鸿蒙Next scheme配置和跳转
目前在应用module.json5中配置了两个uri,如下所述:
"skills": [
{
"entities": [
"entity.system.home",
"entity.system.browsable"
],
"actions": [
"action.system.home",
"ohos.want.action.viewData"
],
"uris": [
{
"scheme": "ryfund",
"host": "xxx"
},
{
"scheme": "foresightfund",
"host": "startapp"
}
],
"domainVerify": true
}
在demo中测试时,ryfund://app.dl.com和foresightfund://startapp,两个uri都可以通过context.openLink拉起。 拉起demo如下:
import { BusinessError } from '[@ohos](/user/ohos).base';
import common from '[@ohos](/user/ohos).app.ability.common';
import Want from '[@ohos](/user/ohos).app.ability.Want';
import { hilog } from '[@kit](/user/kit).PerformanceAnalysisKit';
import { bundleManager, OpenLinkOptions } from '[@kit](/user/kit).AbilityKit';
let context = getContext(this) as common.UIAbilityContext;
function onStartAbility(want: Want) {
context.startAbility(want, (err: BusinessError) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'startAbility failed, code is' + JSON.stringify(err));
return;
}
hilog.info(0x0000, 'testTag', 'startAbility succeed');
});
}
[@Entry](/user/Entry)
[@Component](/user/Component)
struct Index {
build() {
Row() {
Column() {
Button('拉起应用')
.onClick(() => {
const link: string = "foresightfund://startapp";
const link: string = "ryfund://app.dl.com?from=ZhaoShangAPP";
if (!bundleManager.canOpenLink(link)) {
console.error(`cannot open link ${link}`)
return;
}
const openLinkOptions: OpenLinkOptions = { appLinkingOnly: false, parameters: { name: 'test' } };
let context = getContext() as common.UIAbilityContext
context.openLink(link, openLinkOptions).then(() => {
console.info('open link success.');
}).catch((err: BusinessError) => {
console.error(`open link failed. Code is ${err.code}, message is ${err.message}`);
})
}).width('100%')
}.height('100%')
}
}
}
想请问这两个uri有什么区别,为什么会在第三方应用会出现拉起失败的情况呢?
更多关于HarmonyOS 鸿蒙Next scheme配置和跳转的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
处理步骤可参考文档https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/errorcode-bundle-V5#section17700056-指定link的scheme未在queryschemes字段下配置
更多关于HarmonyOS 鸿蒙Next scheme配置和跳转的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙系统中,Next scheme配置和跳转主要涉及应用间的相互访问和数据传递。以下是关于Next scheme配置和跳转的基本说明:
-
配置Next Scheme:
- 在应用的
config.json
文件中,定义你的应用能够响应的scheme。这通常包括一个或多个URI前缀,用于标识你的应用。 - 配置示例(片段):
"module": { "package": "com.example.myapp", "abilities": [ { "name": ".MainAbility", "label": "@string/mainability_full", "icon": "$media:icon", "description": "@string/mainability_description", "visible": "true", "launchType": "singleton", "intentFilter": [ { "action": "android.intent.action.VIEW", "categories": [ "android.intent.category.DEFAULT", "android.intent.category.BROWSABLE" ], "data": [ { "scheme": "https", "host": "www.example.com", "pathPattern": "/myapp/.*" } ] } ] } ] }
- 在应用的
-
跳转:
- 使用Intent携带目标scheme进行跳转。通过构建Intent并设置URI,可以启动目标应用或能力(Ability)。
- 示例代码(伪代码):
let intent = new Intent(); intent.setData(Uri.parse("https://www.example.com/myapp/somepath")); startAbility(intent);
如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html