Application development includes at least two parts: UI page development and bottom-layer feature development. (Some applications that need to be connected to the Internet also involve server development.) The preceding chapters describe how to adapt the pages to devices with different screen sizes. This chapter describes how to address the compatibility issue caused by device system capability differences.
SystemCapability (SysCap) refers to a standalone feature in the operating system, such as Bluetooth, Wi-Fi, NFC, and camera. Each SysCap corresponds to multiple APIs, whose availability depends on the support of the target device.
There are three core concepts related to system capabilities: supported SysCap set, required SysCap set, and associated SysCap set.
During multi-device application development, the default required SysCap set is an intersection of multiple supported SysCap sets, and the default associated SysCap set is a union of multiple supported SysCap sets.
You can determine whether a device supports specific system capabilities at runtime.
You can modify the associated SysCap set and required SysCap set as required.
Dynamic logic determination
If a system capability is not written into the required SysCap set of an application, you need to determine whether the device supports the system capability before using it.
Use canIUse() to check whether a SysCap is supported.
if (canIUse('SystemCapability.Communication.NFC.Core')) {
hilog.info(0x0000, 'Index', `This device supports SystemCapability.Communication.NFC.Core.`);
} else {
hilog.error(0x0000, 'Index', `This device does not support SystemCapability.Communication.NFC.Core.`);
}
Configuring the associated SysCap set and required SysCap set
DevEco Studio automatically configures the associated SysCap set and required SysCap set based on the settings supported by the created project. You can modify these SysCap sets when necessary.
// syscap.json
{
"devices": {
"general": [
"default",
"tablet"
],
"custom": [
{
"Custom Device": [
"SystemCapability.Communication.SoftBus.Core"
]
}
]
},
"development": {
"addedSysCaps": [
"SystemCapability.Communication.NFC.Core"
]
},
"production": {
"addedSysCaps": [],
"removedSysCaps": []
}
}
From application development to usage, the process typically involves application distribution, downloading, installation, and runtime execution. The SysCap mechanism can intercept and control operations at each phase to ensure that applications are installed successfully and function correctly on target devices.
The SysCap mechanism helps you focus on the system capabilities of devices rather than numerous device types, simplifying multi-device application development.