js-apis-enterpriseDeviceManager-DeviceSettingsManager.md 4.4 KB
Newer Older
F
fangyun 已提交
1
# 设备设置管理
F
fangyun 已提交
2

F
fangyun 已提交
3
本模块提供设备设置管理能力,包括设置时间等。仅企业设备管理员应用才能调用。
F
fangyun 已提交
4

F
fangyun 已提交
5 6 7
> **说明**:
> 
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
F
fangyun 已提交
8

F
fangyun 已提交
9 10 11 12 13 14 15
## 使用说明

通过enterpriseDeviceManager中getDeviceSettingsManager方法获取。

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

F
fangyun 已提交
16 17 18 19 20 21 22
enterpriseDeviceManager.getDeviceSettingsManager((error, mgr) => {
    if (error) {
        console.log("error code:" + error.code + " error message:" + error.message);
        return;
    }
    let deviceMgr = mgr;
});
F
fangyun 已提交
23 24
```

F
fangyun 已提交
25 26
## DeviceSettingsManager.setDateTime

F
fangyun 已提交
27
setDateTime(admin: Want, time: number, callback: AsyncCallback\<void>): void
F
fangyun 已提交
28

F
fangyun 已提交
29
设置系统时间。使用callback异步回调。
F
fangyun 已提交
30

F
fangyun 已提交
31
**需要权限:** ohos.permission.ENTERPRISE_SET_DATETIME
F
fangyun 已提交
32 33 34

**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager

L
liwuli 已提交
35 36
**系统API**: 此接口为系统接口。

F
fangyun 已提交
37 38 39 40
**参数:**

| 参数名   | 类型                                  | 必填   | 说明      |
| ----- | ----------------------------------- | ---- | ------- |
F
fangyun 已提交
41 42
| admin | [Want](js-apis-application-Want.md) | 是    | 设备管理员应用。 |
| time  | number | 是 | 时间戳(ms)。 |
Z
zengyawen 已提交
43
| callback | AsyncCallback\<void> | 是 | 回调函数。当系统时间设置成功err为null,否则为错误对象。 |
F
fangyun 已提交
44

L
liwuli 已提交
45 46
**错误码**

L
LiAn 已提交
47
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
L
liwuli 已提交
48

Z
zengyawen 已提交
49
| 类型      | 说明                                                                         |
L
liwuli 已提交
50 51 52 53
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not a administrator of the device.                        |
| 9200002 | The administrator application does not have permission to manage the device. |

F
fangyun 已提交
54 55 56
**示例:**

```js
F
fangyun 已提交
57 58
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager'

F
fangyun 已提交
59 60 61 62
let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
F
fangyun 已提交
63
enterpriseDeviceManager.getDeviceSettingsManager((error, mgr) => {
F
fangyun 已提交
64
    if (error) {
F
fangyun 已提交
65 66
        console.log("error code:" + error.code + " error message:" + error.message);
        return;
F
fangyun 已提交
67
    }
F
fangyun 已提交
68 69 70 71 72
    mgr.setDateTime(wantTemp, 1526003846000, (error) => {
        if (error) {
            console.log("error code:" + error.code + " error message:" + error.message);
        }
    });
F
fangyun 已提交
73
});
F
fangyun 已提交
74 75
```

F
fangyun 已提交
76
## DeviceSettingsManager.setDateTime
F
fangyun 已提交
77

F
fangyun 已提交
78
setDateTime(admin: Want, time: number): Promise\<void>
F
fangyun 已提交
79

F
fangyun 已提交
80
设置系统时间。使用Promise异步回调。
F
fangyun 已提交
81

F
fangyun 已提交
82
**需要权限:** ohos.permission.ENTERPRISE_SET_DATETIME
F
fangyun 已提交
83 84 85

**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager

L
liwuli 已提交
86 87
**系统API**: 此接口为系统接口。

F
fangyun 已提交
88 89 90 91
**参数:**

| 参数名   | 类型                                  | 必填   | 说明      |
| ----- | ----------------------------------- | ---- | ------- |
F
fangyun 已提交
92 93
| admin | [Want](js-apis-application-Want.md) | 是    | 设备管理员应用。 |
| time  | number | 是 | 时间戳(ms)。 |
F
fangyun 已提交
94 95 96 97 98

**返回值:**

| 类型   | 说明                                  |
| ----- | ----------------------------------- |
Z
zengyawen 已提交
99
| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
F
fangyun 已提交
100

L
liwuli 已提交
101 102
**错误码**

L
LiAn 已提交
103
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
L
liwuli 已提交
104

Z
zengyawen 已提交
105
| 类型      | 说明                                                                         |
L
liwuli 已提交
106 107 108
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not a administrator of the device.                        |
| 9200002 | The administrator application does not have permission to manage the device. |
F
fangyun 已提交
109 110 111 112

**示例:**

```js
F
fangyun 已提交
113 114
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager'

F
fangyun 已提交
115 116 117 118
let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
F
fangyun 已提交
119 120 121 122 123
enterpriseDeviceManager.getDeviceSettingsManager().then((mgr) => {
    mgr.setDateTime(wantTemp, 1526003846000).then(() => {
    }).catch((error) => {
        console.log("error code:" + error.code + " error message:" + error.message);
    })
F
fangyun 已提交
124
}).catch((error) => {
F
fangyun 已提交
125
    console.log("error code:" + error.code + " error message:" + error.message);
F
fangyun 已提交
126 127
})
```