harmony 鸿蒙@ohos.enterprise.deviceSettings (Device Settings)
@ohos.enterprise.deviceSettings (Device Settings)
The deviceSettings module provides APIs for setting enterprise devices, including obtaining the screen-off time of a device.
NOTE
The initial APIs of this module are supported since API version 12. 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 of this module can be called only by a device administrator application that is enabled.
Modules to Import
import { deviceSettings } from '@kit.MDMKit';
deviceSettings.setValue
setValue(admin: Want, item: string, value: string): void
Sets a device setting policy.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SETTINGS
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
item | string | Yes | Type of the policy to set. - screenOff: screen-off policy. For 2-in-1 devices, only the screen-off policy in battery mode can be set. - dateTime: system time settings. - powerPolicy: device power policy. For 2in1 devices, only the power policy in battery mode can be set. |
value | string | Yes | Policy to set. If item is screenOff, value is the screen-off time, in ms. If item is dateTime, value is the system time to set, in ms. If item is powerPolicy, value is a JSON string in {“powerScene”:xx,“powerPolicy”:{“powerPolicyAction”:xx,“delayTime”:xx}} format. powerScene specifies the power policy scenario; delayTime specifies the delay time in ms (it cannot be set to 30000 ms); powerPolicyAction specifies the sleep policy. The value of powerScene can be: - 0: timeout. The value of powerPolicyAction can be: - 0: No action is performed. - 1: enter sleep mode automatically. - 2: forcibly enter sleep mode. - 3: enter sleep mode (not supported by the power subsystem currently). - 4: power off. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
deviceSettings.setValue(wantTemp, 'screenOff', '3000');
console.info(`Succeeded in setting screen off time.`);
} catch (err) {
console.error(`Failed to set screen off time. Code: ${err.code}, message: ${err.message}`);
}
deviceSettings.getValue
getValue(admin: Want, item: string): string
Obtains a device setting policy.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SETTINGS
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
item | string | Yes | Type of the policy to set. - screenOff: screen-off policy of a device. For a 2-in-1 device, only the screen-off policy in battery mode can be obtained. - dateTime: system time settings. - powerPolicy: device power policy. For 2-in-1 devices, only the power policy in battery mode can be obtained. |
Return value
Type | Description |
---|---|
string | Policy obtained. If item is screenOff, the device screen-off time (in ms) is returned. For a 2-in-1 device, the device screen-off time (in ms) in battery mode is returned. If item is dateTime, the system time (in ms) is returned. If item is powerPolicy, the power policy is returned. For a 2-in-1 device, the power policy in battery mode is returned. The power policy a JSON string in {“powerScene”:xx,“powerPolicy”:{“powerPolicyAction”:xx,“delayTime”:xx}} format. powerScene indicates the power policy scenario, delayTime indicates the delay time (in ms), and powerPolicyAction indicates the sleep policy. The value of powerScene can be: - 0: timeout. The value of powerPolicyAction can be: - 0: No action is performed. - 1: enter sleep mode automatically. - 2: forcibly enter sleep mode. - 3: enter sleep mode (not supported by the power subsystem currently). - 4: power off. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
let result: string = deviceSettings.getValue(wantTemp, 'screenOff');
console.info(`Succeeded in getting screen off time, result : ${result}`);
} catch (err) {
console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`);
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Enterprise Device Management Error Codes
harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)
harmony 鸿蒙@ohos.enterprise.accountManager (Account Management) (System API)
harmony 鸿蒙@ohos.enterprise.accountManager (Account Management)
harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management) (System API)
harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management)
harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management (System API)
harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management)
harmony 鸿蒙@ohos.enterprise.bluetoothManager (Bluetooth Management) (System API)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦