harmony 鸿蒙@ohos.enterprise.deviceInfo (Device Information Management)

  • 2023-02-03
  • 浏览 (588)

@ohos.enterprise.deviceInfo (Device Information Management)

The deviceInfo module provides APIs for enterprise device information management, including the API for obtaining device serial numbers.

NOTE

  • The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • The APIs of this module can be used only in the stage model.

  • The APIs provided by this module can be called only by a device administrator application that is enabled.

Modules to Import

import deviceInfo from '@ohos.enterprise.deviceInfo';

deviceInfo.getDeviceSerial

getDeviceSerial(admin: Want, callback: AsyncCallback<string>): void

Obtains the device serial number through the specified device administrator application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_DEVICE_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.
callback AsyncCallback<string> Yes Callback invoked to return the result. If the operation is successful, err is null and data is the device serial number obtained. If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

ID Error Message
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

deviceInfo.getDeviceSerial(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get device serial. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting device serial, result : ${result}`);
});

deviceInfo.getDeviceSerial

getDeviceSerial(admin: Want): Promise<string>

Obtains the device serial number through the specified device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_DEVICE_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.

Return value

Type Description
Promise<string> Promise used to return the device serial number.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

ID Error Message
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

deviceInfo.getDeviceSerial(wantTemp).then((result) => {
  console.info(`Succeeded in getting device serial, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get device serial. Code: ${err.code}, message: ${err.message}`);
});

deviceInfo.getDisplayVersion

getDisplayVersion(admin: Want, callback: AsyncCallback<string>): void;

Obtains the device version through the specified device administrator application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_DEVICE_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.
callback AsyncCallback<string> Yes Callback invoked to return the result. If the operation is successful, err is null and data is the device version obtained. If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

ID Error Message
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

deviceInfo.getDisplayVersion(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get display version. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting display version, result : ${result}`);
});

deviceInfo.getDisplayVersion

getDisplayVersion(admin: Want): Promise<string>

Obtains the device version through the specified device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_DEVICE_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.

Return value

Type Description
Promise<string> Promise used to return the device version obtained.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

ID Error Message
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

deviceInfo.getDisplayVersion(wantTemp).then((result) => {
  console.info(`Succeeded in getting display version, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get display version. Code: ${err.code}, message: ${err.message}`);
});

deviceInfo.getDeviceName

getDeviceName(admin: Want, callback: AsyncCallback<string>): void

Obtains the device name through the specified device administrator application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_DEVICE_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.
callback AsyncCallback<string> Yes Callback invoked to return the result. If the operation is successful, err is null and data is the device name obtained. If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

ID Error Message
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

deviceInfo.getDeviceName(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get device name. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting device name, result : ${result}`);
});

deviceInfo.getDeviceName

getDeviceName(admin: Want): Promise<string>

Obtains the device name through the specified device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_GET_DEVICE_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.

Return value

Type Description
Promise<string> Promise used to return the device name.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

ID Error Message
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

deviceInfo.getDeviceName(wantTemp).then((result) => {
  console.info(`Succeeded in getting device name, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get device name. Code: ${err.code}, message: ${err.message}`);
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞