HarmonyOS鸿蒙Next中通过DeepLink方式拉起应用,应用未被拉起!
HarmonyOS鸿蒙Next中通过DeepLink方式拉起应用,应用未被拉起! 目前存在一个很奇葩的现象 被拉起应用只有退出登录重新登录后 通过deepLink就无法拉起应用了,下面是deeplink拉起代码:
private openMbsClientToAuth(builder: Builder) {
const link = 'test://abcdefg:hi';
let context = getContext() as common.UIAbilityContext;
let openLinkOptions: OpenLinkOptions = {
appLinkingOnly: false,
parameters: {
sdkAuth: true,
sdkAuthPkg: builder.packageName,
sdkAppkey: builder.appKey,
sdkSecretkey: builder.secretKey,
sdkName: "ssoauth"
}
};
ZLog.i(TAG, 'openMbsClientToAuth-- openLinkOptions = ' + JSON.stringify(openLinkOptions));
context.openLink(link, openLinkOptions, (err: BusinessError, result: common.AbilityResult) => {
if (err) {
ZLog.e(TAG, 'Failed to open link err.code = ' + err.code + '---err.message = ' + err.message);
if (this.uuSsoAuthListener) {
this.uuSsoAuthListener(false, null, err.code, err.message);
}
} else {
if (result && result.want && result.want.parameters) {
let authdata = result.want.parameters.authdata as string;
let errorMsg = result.want.parameters.errorMsg as string;
ZLog.i(TAG, 'Successfully opened link errorMsg = ' + errorMsg + '----authdata =' + authdata);
if (authdata && authdata.length > 0) {
// 保存信息
let ssoAuthParam = JSON.parse(authdata) as UUMbsSsoAuthParam
if (this.uuSsoAuthListener) {
this.uuSsoAuthListener(true, ssoAuthParam, UUMbsRspCode.MbsSuccess, null);
}
} else {
if (this.uuSsoAuthListener) {
this.uuSsoAuthListener(false, null, UUMbsRspCode.MbsErrCodeCommon, errorMsg);
}
}
}
}
})
.then(() => {
ZLog.i(TAG, 'Link opened successfully.');
})
}
context.openLink执行后日志 ZLog.i(TAG, ‘Link opened successfully.’);会被打印出来,但是被拉起应用的 oncreate()和onNewWant()均为被执行,应用未被拉起
被拉起应用的module.json5的skills配置如下:
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
},{
"actions": [
"ohos.want.action.viewData"
],
"uris": [
{
// scheme必选,可以自定义,以link为例,需要替换为实际的scheme
"scheme": "test",
// host必选,配置待匹配的域名
"host": "abcdefg",
"port": "hi"
}
]
}
]
更多关于HarmonyOS鸿蒙Next中通过DeepLink方式拉起应用,应用未被拉起!的实战教程也可以访问 https://www.itying.com/category-93-b0.html
被拉起应用的 oncreate()和onNewWant()均未被执行,
更多关于HarmonyOS鸿蒙Next中通过DeepLink方式拉起应用,应用未被拉起!的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中,通过DeepLink方式拉起应用时,如果应用未被拉起,可能的原因包括:
-
DeepLink配置错误:检查应用的
config.json
文件中是否正确配置了uri
和ability
。确保uri
与调用DeepLink时使用的URI一致,且ability
指向正确的Ability。 -
应用未安装或未启动:确保目标应用已正确安装并处于可运行状态。如果应用未安装或未启动,DeepLink无法拉起应用。
-
权限问题:检查应用是否具备必要的权限,如
ohos.permission.START_ABILITIES
,以确保能够通过DeepLink拉起其他应用。 -
URI格式错误:确保调用DeepLink时使用的URI格式正确,包括协议、主机、路径等部分。URI应与
config.json
中配置的uri
完全匹配。 -
应用未注册DeepLink:确保目标应用在
config.json
中正确注册了DeepLink。未注册DeepLink的应用无法通过DeepLink方式拉起。 -
系统版本兼容性:检查HarmonyOS版本是否支持DeepLink功能。某些旧版本可能不支持或存在兼容性问题。
-
应用状态异常:如果目标应用处于异常状态(如崩溃、冻结等),DeepLink可能无法正常拉起应用。
-
日志分析:通过查看系统日志或应用日志,分析DeepLink调用过程中是否存在错误或异常信息,以进一步定位问题。
通过以上步骤,可以排查并解决HarmonyOS鸿蒙Next中通过DeepLink方式拉起应用时应用未被拉起的问题。
在HarmonyOS鸿蒙Next中,通过DeepLink方式拉起应用时,如果应用未被拉起,可能的原因包括:
-
DeepLink配置错误:确保在
config.json
中正确配置了uri
和action
,且与应用的实际处理逻辑匹配。 -
应用未安装或未启动:确保目标应用已安装并处于可运行状态。
-
权限问题:检查是否已授予相关权限,如
ohos.permission.START_ABILIT
。 -
URI格式错误:确认DeepLink的URI格式正确,且与应用注册的URI一致。
-
应用未处理DeepLink:确保应用已实现处理DeepLink的逻辑,如
onStart
方法中正确解析URI。
建议逐一排查以上问题,确保DeepLink配置和应用逻辑正确无误。