js-apis-enterpriseDeviceManager-DeviceSettingsManager.md 4.3 KB
Newer Older
E
ester.zhou 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# Device Settings Management

The **EnterpriseDeviceManager** module provides capabilities to manage device settings, such as time settings. The APIs of this module can only be called by enterprise device administrator applications.

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

## Usage

Before calling any API in **EnterpriseDeviceManager**, use **getDeviceSettingsManager** to create an **EnterpriseDeviceManager** instance.

```js
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager'

enterpriseDeviceManager.getDeviceSettingsManager((error, mgr) => {
    if (error) {
        console.log("error code:" + error.code + " error message:" + error.message);
        return;
    }
    let deviceMgr = mgr;
});
```

## DeviceSettingsManager.setDateTime

E
ester.zhou 已提交
27
setDateTime(admin: Want, time: number, callback: AsyncCallback\<void>): void
E
ester.zhou 已提交
28 29 30

Sets the system time. This API uses an asynchronous callback to return the result.

E
ester.zhou 已提交
31
**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME
E
ester.zhou 已提交
32 33 34

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

E
ester.zhou 已提交
35 36
**System API**: This is a system API.

E
ester.zhou 已提交
37 38 39 40 41 42
**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-application-Want.md) | Yes   | Device administrator application.|
| time  | number | Yes| Timestamp (ms).|
E
ester.zhou 已提交
43
| callback | AsyncCallback\<void> | Yes| Callback used to the result. If the system time is set successfully, **err** is **null**; otherwise, **err** is an error object.|
E
ester.zhou 已提交
44

E
ester.zhou 已提交
45 46 47 48 49 50 51
**Error codes**

| Type     | Description                                                                        |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not a administrator of the device.                        |
| 9200002 | The administrator application does not have permission to manage the device. |

E
ester.zhou 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
**Example**

```js
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager'

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.getDeviceSettingsManager((error, mgr) => {
    if (error) {
        console.log("error code:" + error.code + " error message:" + error.message);
        return;
    }
    mgr.setDateTime(wantTemp, 1526003846000, (error) => {
        if (error) {
            console.log("error code:" + error.code + " error message:" + error.message);
        }
    });
});
```

## DeviceSettingsManager.setDateTime

E
ester.zhou 已提交
76
setDateTime(admin: Want, time: number): Promise\<void>
E
ester.zhou 已提交
77 78 79

Sets the system time. This API uses a promise to return the result.

E
ester.zhou 已提交
80
**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME
E
ester.zhou 已提交
81 82 83

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

E
ester.zhou 已提交
84 85
**System API**: This is a system API.

E
ester.zhou 已提交
86 87 88 89 90 91 92 93 94 95 96
**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-application-Want.md) | Yes   | Device administrator application.|
| time  | number | Yes| Timestamp (ms).|

**Return value**

| Type  | Description                                 |
| ----- | ----------------------------------- |
E
ester.zhou 已提交
97
| Promise\<void> | Promise that returns no value.|
E
ester.zhou 已提交
98

E
ester.zhou 已提交
99 100 101 102 103 104 105
**Error codes**

| Type     | Description                                                                        |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not a administrator of the device.                        |
| 9200002 | The administrator application does not have permission to manage the device. |

E
ester.zhou 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
**Example**

```js
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager'

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.getDeviceSettingsManager().then((mgr) => {
    mgr.setDateTime(wantTemp, 1526003846000).then(() => {
    }).catch((error) => {
        console.log("error code:" + error.code + " error message:" + error.message);
    })
}).catch((error) => {
    console.log("error code:" + error.code + " error message:" + error.message);
})
```