Permissions required for device connection in HarmonyOS development
In Hongmeng development, if we directly use
DeviceManager.getDeviceList(0);
To obtain the device connected to the terminal, the following error will be reported:
The reason for the error is that the corresponding permissions have not been applied for. The most basic permissions we need to apply for device connection are as follows (inconfig.jsonundermodule objectApply for permissions in):
"reqPermissions": [
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC"},
{
"name": "ohos.permission.DISTRIBUTED_DEVICE_STATE_CHANGE"},
{
"name": "ohos.permission.GET_DISTRIBUTED_DEVICE_INFO" },
{
"name": "ohos.permission.GET_BUNDLE_INFO"}
],
Running again can run successfully, and you can check which devices are successfully connected to the terminal.