HarmonyOS Native SDK
Device Management
Device Lists

Device Lists

GizDeviceManager maintains a unified cache shared by BLE, LAN, and cloud-bound devices. GizUserManager synchronizes the current user's cloud-bound list.

Observe and refresh bound devices

import { GizBoundDeviceProfile, GizSDKManager } from '@gizwits/smart-sdk';
 
const userManager = GizSDKManager.getUserManager();
const unsubscribeBound = userManager.subscribeBoundDeviceList().subscribe(
  (profiles: Array<GizBoundDeviceProfile>): void => {
    // Copy cloud-bound profiles into ArkUI state.
  }
);
 
const profiles = await userManager.refreshBoundDeviceList();

queryBoundDevices() is the compatibility name for an active refresh. The MQTT module uses the returned service addresses and credentials to establish cloud transports.

Read unified device lists

import { GizDeviceManager } from '@gizwits/smart-sdk';
 
const allDevices = GizDeviceManager.getRegisteredDevices();
const boundDevices = GizDeviceManager.getBoundDevices();
const bluetoothDevices = GizDeviceManager.getBluetoothDevices();
const lanDevices = GizDeviceManager.getLanDevices();
 
const unsubscribeDevices = GizDeviceManager.subscribeDeviceList().subscribe((devices): void => {
  // A device list or device state changed in any source.
});

Call unsubscribeBound() and unsubscribeDevices() when the page is destroyed. Do not call SDK-internal state mutation methods.