harmony 鸿蒙(Optional) Using canOpenLink to Check Application Accessibility
(Optional) Using canOpenLink to Check Application Accessibility
When to Use
Before starting application B, application A can call canOpenLink to check whether application B is accessible.
NOTE
The canOpenLink API cannot be used to determine whether the application navigated to via App Linking is installed.
Constraints
A maximum of 50 URL schemes can be configured in the querySchemes field in the module.json5 file of the entry module.
Available APIs
canOpenLink is provided by the bundleManager module to check whether a target application is accessible.
For details about the matching rules, see Matching Rules of Explicit Want and Implicit Want.
How to Develop
Procedure for the Caller Application
Configure the querySchemes field in the module.json5 file of the entry module to declare the URL schemes.
{ "module": { //... "querySchemes": [ "app1Scheme" ] } }
Import the ohos.bundle.bundleManager module.
Call canOpenLink.
import { bundleManager } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; try { let link = 'app1Scheme://test.example.com/home'; let canOpen = bundleManager.canOpenLink(link); hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(canOpen)); } catch (err) { let message = (err as BusinessError).message; hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message); }
Procedure for the Target Application
Configure the uris field in the module.json5 file.
{
"module": {
//...
"abilities": [
{
//...
"skills": [
{
// actions cannot be empty. Otherwise, matching the target application fails.
"actions": ["ohos.want.action.home"],
"uris": [
{
"scheme": "app1Scheme",
"host": "test.example.com",
"pathStartWith": "home"
}
]
}
]
}
]
}
}
FAQ
- Why is there a limit of 50 URL schemes in querySchemes?
The canOpenLink() API is used to check whether an application is accessible. It indirectly reveals whether a specific application is installed.
To protect system security and user privacy and to prevent malicious applications from scanning the list of installed applications, you must configure the querySchemes property when using the canOpenLink() API. The maximum number of URL schemes that can be configured is 50.
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Obtaining Reasons for Abnormal Application Exits
harmony 鸿蒙UIAbility Backup and Restore
harmony 鸿蒙Using Explicit Want to Start an Application Component
harmony 鸿蒙Introduction to Ability Kit
harmony 鸿蒙AbilityStage Component Container
harmony 鸿蒙Accessing a DataAbility
harmony 鸿蒙Accessing a DataShareExtensionAbility from the FA Model
harmony 鸿蒙Common action and entities Values (Not Recommended)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦