目录

Cross-Device Feature Development

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.

System Capability

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.

  • An application can be distributed, installed, and run on a device only when the required SysCap set is a subset of the device's supported SysCap set.
  • For details about how to use system capabilities, see SystemCapability.

Multi-Device Application Development

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.

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.

  • If a system capability is necessary for application running, this system capability must be written into the required SysCap set of the application to ensure that the application is not distributed or installed on a device that does not meet the requirements.
  • If a system capability is not necessary for application running, dynamic determination can be performed during runtime. In this way, the application scope can be expanded to the maximum extent.

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": []     
    }
}
  • Exercise caution when modifying the required SysCap set. Incorrect modifications may render the application unable to be distributed to or installed on the target device.
  • For the associated SysCap set, add system capabilities to expand the API scope that can be associated by DevEco Studio. Note that these APIs may not be supported on all devices. Always verify the availability of an API before usage.

Summary

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.