public class DeviceManager extends Object
You can call getLocalDeviceInfo() to query basic information about a local device.
After trusted devices have been networked, getTrustedDeviceList(java.lang.String,java.util.Map)
can be called to obtain the trusted device list.
You can call registerDeviceStateCallback(java.lang.String,java.util.Map,ohos.distributedhardware.devicemanager.DeviceStateCallback) to
register device state callbacks to listen for state changes of a device. When a trusted device goes online or
offline, the particular callback defined in DeviceStateCallback will be called to notify your application
of the online or offline device information.
If your application no longer needs to be notified of device state changes, you can call
unregisterDeviceStateCallback(java.lang.String,ohos.distributedhardware.devicemanager.DeviceStateCallback) to unregister all previously registered
callbacks to stop listening for state changes of a trusted device.
After selectDeviceList(java.lang.String,java.util.Map,ohos.distributedhardware.devicemanager.SelectDeviceListListener) is called, the
list of available devices will be displayed on the screen for the user to select. After the user chooses a desired
device, SelectDeviceListListener will be triggered to notify your application of the information and state
of the selected device.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static interface |
DeviceManager.DeviceManagerCallback |
Provides callbacks for getting
DeviceManager instance. |
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static String |
SIFT_FILTER |
Indicates the field name for the filtering parameter.
|
static String |
SORT_TYPE |
Indicates the field name for the sorting type.
|
static String |
TARGET_PACKAGE_NAME |
Indicates the field name for the target application bundle name.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static int |
createInstance(DeviceManager.DeviceManagerCallback callback) |
Creates a
DeviceManager instance. |
DeviceInfo |
getLocalDeviceInfo() |
Obtains the local device information.
|
List<DeviceInfo> |
getTrustedDeviceList(String bundleName,
Map<String,Object> extras) |
Obtains a list of trusted devices.
|
int |
registerDeviceStateCallback(String bundleName,
Map<String,Object> extras,
DeviceStateCallback callback) |
Registers a device state callback so that the application can be notified upon device state changes based on
the application bundle name and filtering parameter.
|
static void |
releaseInstance() |
Releases the
DeviceManager instance after the methods for device management are no longer used. |
int |
selectDeviceList(String bundleName,
Map<String,Object> extras,
SelectDeviceListListener listener) |
Presents the candidate device list on the UI for the user to select and notifies the application of the
selected device.
|
int |
unregisterDeviceStateCallback(String bundleName,
DeviceStateCallback callback) |
Unregisters the device state callback.
|
public static final String SIFT_FILTER
public static final String SORT_TYPE
If this field is not specified during device query, the devices are not sorted by default. In this case,
SIFT_FILTER must be specified.
public static final String TARGET_PACKAGE_NAME
If this field is specified during trusted device query, application-level trusted devices are filtered to ensure that the specified application is in the group of application-level trusted devices and a list containing both device- and application-level trusted devices will be returned. If this field is not specified, only a list of device-level trusted devices will be provided. Device-level trusted devices include devices with the same account or those with different accounts but in the public group.
public static int createInstance(DeviceManager.DeviceManagerCallback callback)
DeviceManager instance.
To manage devices, you must first call this method to obtain a DeviceManager instance and then
use this instance to call other device management methods.
callback - Indicates the callback to be invoked upon DeviceManager instance creation. The
instance will be carried in DeviceManagerCallback#onGet(DeviceManager) after being created,
and your application will be notified via DeviceManagerCallback#onDied() if the instance is
destroyed.ReturnCode.public static void releaseInstance()
DeviceManager instance after the methods for device management are no longer used.public List<DeviceInfo> getTrustedDeviceList(String bundleName, Map<String,Object> extras) throws SecurityException
bundleName - Indicates the bundle name of the application.extras - Indicates the extra parameters to be passed to this method for device filtering or sorting.
This parameter can be null. For details about available values, see TARGET_PACKAGE_NAME and
SORT_TYPE.SecurityException - Throws this exception if the application does not have the required permission.public int selectDeviceList(String bundleName, Map<String,Object> extras, SelectDeviceListListener listener) throws SecurityException
bundleName - Indicates the bundle name of the application.extras - Indicates the extra parameters to be passed to this method for device filtering or sorting.
This parameter cannot be null. For details about available values, see TARGET_PACKAGE_NAME,
SORT_TYPE, and SIFT_FILTER.listener - Indicates the callback invoked for notifying the application of the selected device and its
state. For details, see SelectDeviceListListener.ReturnCode.SecurityException - Throws this exception if the application does not have the required permission.public DeviceInfo getLocalDeviceInfo() throws SecurityException
DeviceInfo object containing the local device information.SecurityException - Throws this exception if the application does not have the required permission.public int registerDeviceStateCallback(String bundleName, Map<String,Object> extras, DeviceStateCallback callback) throws SecurityException
bundleName - Indicates the bundle name of the application.extras - Indicates the extra parameters to be passed to this method for device filtering or sorting.
This parameter can be null. For details about available values, see TARGET_PACKAGE_NAME and
SIFT_FILTER.callback - Indicates the device state callback to register. For details, see DeviceStateCallback.ReturnCode.SecurityException - Throws this exception if the application does not have the required permission.public int unregisterDeviceStateCallback(String bundleName, DeviceStateCallback callback) throws SecurityException
bundleName - Indicates the bundle name of the application.callback - Indicates the device state callback to unregister. For details, see DeviceStateCallback.ReturnCode.SecurityException - Throws this exception if the application does not have the required permission.