Arkts进阶<应用间跳转 - 判断应用是否可访问>
Arkts进阶<应用间跳转 - 判断应用是否可访问>
当我们想要在拉起指定应用之前,判断当前应用是否在当前设备上已安装的时候,一种是直接调用拉起三方应用的方法:如DeepLinking中提到的使用openLink进行操作,如果设备没有安装应用,那么方法抛出异常。
另一种处理方式就是使用canOpenLink方法进行判断,下面针对canOpenLink进行讲解。
获取跳转目标的配置
1、获取已安装应用的bundleName
hdc shell bm dump -a // 获取所有安装应用的bundleName
hdc shell aa dump -l // 获取当前打开应用的bundleName
2、获取应用的完整配置信息,包括abilities、skills、uris等配置。
hdc shell bm dump -n www.example.com
获取信息如下:
// 输出示例(skills部分):
// ...
"name": "EntryAbility",
// ...
{
"skills": [
{
"actions": [
"ohos.want.action.viewData"
],
"domainVerify": false,
"entities": [
"entity.system.browsable"
],
"permissions": [],
"uris": [
{
"host": "www.example.com",
"linkFeature": "",
"maxFileSupported": 0,
"path": "path1",
"pathRegex": "",
"pathStartWith": "",
"port": "",
"scheme": "appurl",
"type": "",
"utd": ""
}
]
}
]
}
约束限制
1、在entry模块的module.json5文件中的querySchemes字段中,从API version 21开始,最多允许配置200个URL scheme。API version 20及之前的版本,最多允许配置50个URL scheme。
2、canOpenLink接口不支持判断以App Linking方式跳转的目标应用是否可访问。
接口说明
canOpenLink是bundleManager提供的支持判断目标应用是否可访问的接口。
匹配规则请参考显式Want与隐式Want匹配规则。
操作步骤
1、拉起方配置:
在entry模块的module.json5文件中配置querySchemes属性,声明想要查询的URL scheme。
{
"module": {
"querySchemes": [
"app1Scheme"
]
}
}
调用canOpenLink接口。
try {
let link = 'app1Scheme://test.example.com/home';
let canOpen = bundleManager.canOpenLink(link); // 返回boolean值
} catch (err) {
let message = (err as BusinessError).message;
}
2、被拉起方配置:
在module.json5文件中配置uris属性。
{
"module": {
"abilities": [
{
"skills": [
{
// actions不能为空,actions为空会造成目标方匹配失败
"actions": [
"ohos.want.action.home"
],
"uris": [
{
"scheme": "app1Scheme",
"host": "test.example.com",
"pathStartWith": "home"
}
]
}
]
}
]
}
}
这一章节很简单,主要是三方的module.json5的配置和拉起方的跳转uri要对应的上。也就是说如果拉起方的uri为:
let link = 'app1Scheme://';
那么被拉起方的配置要为:
"uris": [
{
"scheme": "app1Scheme"
}
]
在开发过程中因为三方的配置我们未知,所以可以参考Android或/iOS的跳转配置进行尝试配置。
更多推荐



所有评论(0)