未验证 提交 e97555c9 编写于 作者: O openharmony_ci 提交者: Gitee

!2090 update docs:中英文网站目录调整+Misc子系统资料交付

Merge pull request !2090 from zengyawen/master
此差异已折叠。
......@@ -13,13 +13,8 @@
- [Audio Recording Development](audio-recorder.md)
- [Audio Recorder Development Using AudioCapturer](audio-capturer)
- Video
- [Video Playback Development](video-playback.md)
- [Video Recording Development](video-recorder.md)
- Sound
- [SoundManager Development](sound-manager.md)
# 应用开发
- [应用开发导读](application-dev-guide.md)
- 了解OpenHarmony
- [了解OpenHarmony开源项目](../OpenHarmony-Overview_zh.md)
- [了解OpenHarmony系统](../readme)
- [术语](../device-dev/glossary/glossary.md)
- [版本说明](../release-notes/Readme.md)
- OpenHarmony 3.x Releases
......@@ -30,7 +25,6 @@
- [OpenHarmony 1.1.1 LTS (2021-06-22)](../release-notes/OpenHarmony-1-1-1-LTS.md)
- [OpenHarmony 1.1.0 LTS (2021-04-01)](../release-notes/OpenHarmony-1-1-0-LTS.md)
- [OpenHarmony 1.0 (2020-09-10)](../release-notes/OpenHarmony-1-0.md)
- 快速开始
- [应用开发快速入门](quick-start/Readme-CN.md)
- DevEco Studio(OpenHarmony)使用指南
......@@ -43,7 +37,6 @@
- [配置OpenHarmony应用签名信息](quick-start/configuring-openharmony-app-signature.md)
- [安装运行OpenHarmony应用](quick-start/installing-openharmony-app.md)
- [应用开发包结构说明](quick-start/quick-start/package-structure.md)
- 开发
- [Ability开发](ability/Readme-CN.md)
- [Ability框架概述](ability/ability-brief.md)
......@@ -262,7 +255,6 @@
- 分布式跟踪
- [分布式跟踪概述](dfx/hitracechain-overview.md)
- [分布式跟踪开发指导](dfx/hitracechain-guidelines.md)
- 工具
- [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- [概述](quick-start/deveco-studio-overview.md)
......@@ -271,12 +263,10 @@
- [创建OpenHarmony工程](quick-start/create-openharmony-project.md)
- [配置OpenHarmony应用签名信息](quick-start/configuring-openharmony-app-signature.md)
- [安装运行OpenHarmony应用](quick-start/installing-openharmony-app.md)
- 示例教程
- [示例代码](https://gitee.com/openharmony/app_samples/blob/master/README_zh.md)
- [Codelabs](https://gitee.com/openharmony/codelabs/blob/master/README.md)
- API参考
- [组件参考(基于JS扩展的类Web开发范式)](reference/arkui-js/Readme-CN.md)
- 组件
......@@ -644,7 +634,6 @@
- 定制管理
- [配置策略](reference/apis/js-apis-config-policy.md)
- [企业设备管理](reference/apis/js-apis-enterprise-device-manager.md)
- 贡献
- [参与贡献](../contribute/贡献文档.md)
\ No newline at end of file
......@@ -54,6 +54,7 @@
- [Socket连接](js-apis-socket.md)
- [WebSocket连接](js-apis-webSocket.md)
- [数据请求](js-apis-http.md)
- [上传下载](js-apis-request.md)
- 通信与连接
- [WLAN](js-apis-wifi.md)
- [Bluetooth](js-apis-bluetooth.md)
......@@ -81,7 +82,10 @@
- [弹窗](js-apis-basic-features-pop-up.md)
- [应用配置](js-apis-basic-features-configuration.md)
- [定时器](js-apis-basic-features-timer.md)
- [锁屏管理](js-apis-screen-lock.md)
- [设置系统时间](js-apis-system-time.md)
- [壁纸](js-apis-wallpaper.md)
- [剪贴板](js-apis-pasteboard.md)
- [动画](js-apis-basic-features-animator.md)
- [WebGL](js-apis-webgl.md)
- [WebGL2](js-apis-webgl2.md)
......
此差异已折叠。
# 锁屏管理
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```
import screenlock from '@ohos.screenLock';
```
## screenlock.isScreenLocked
isScreenLocked(callback: AsyncCallback<boolean>): void
判断屏幕是否锁屏,使用callback作为异步方法。
**系统能力**: SystemCapability.MiscServices.ScreenLock
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | 是 | 回调函数,返回true表示屏幕已锁屏,返回false表示屏幕未锁屏。 |
- 示例:
```
screenlock.isScreenLocked((err, data)=>{
if (err) {
console.error('isScreenLocked callback error -> ${JSON.stringify(err)}');
return;
}
console.info('isScreenLocked callback success data -> ${JSON.stringify(data)}');
});
```
## screenlock.isScreenLocked
isScreenLocked(): Promise<boolean>
判断屏幕是否锁屏,使用Promise作为异步方法。
**系统能力**: SystemCapability.MiscServices.ScreenLock
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise<boolean> | 以Promise形式返回结果。 |
- 示例:
```
screenlock.isScreenLocked().then((data) => {
console.log('isScreenLocked success: data -> ${JSON.stringify(data)}');
}).catch((err) => {
console.error('isScreenLocked fail, promise: err -> ${JSON.stringify(err)}');
});
```
## screenlock.isSecureMode
isSecureMode(callback: AsyncCallback<boolean>): void
判断设备是否处于安全模式下,使用callback作为异步方法。
**系统能力**: SystemCapability.MiscServices.ScreenLock
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示屏幕处于安全模式下,返回false表示屏幕当前不在安全模式下。 |
- 示例:
```
screenlock.isSecureMode((err, data)=>{
if (err) {
console.error('isSecureMode callback error -> ${JSON.stringify(err)}');
return;
}
console.info('isSecureMode callback success data -> ${JSON.stringify(err)}');
});
```
## screenlock.isSecureMode
isSecureMode(): Promise<boolean>
判断设备是否处于安全模式下,使用Promise作为异步方法。
**系统能力**: SystemCapability.MiscServices.ScreenLock
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise<boolean> | 以Promise形式返回结果。 |
- 示例:
```
screenlock.isSecureMode().then((data) => {
console.log('isSecureMode success: data->${JSON.stringify(data)}');
}).catch((err) => {
console.error('isSecureMode fail, promise: err->${JSON.stringify(err)}');
});
```
## screenlock.unlockScreen
unlockScreen(callback: AsyncCallback<void>): void
解锁屏幕,使用callback作为异步方法。
**系统能力**: SystemCapability.MiscServices.ScreenLock
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | 是 | 回调函数,失败时返回错误信息。 |
- 示例:
```
screenlock.unlockScreen((err)=>{
if (err) {
console.error('unlockScreen callback error -> ${JSON.stringify(err)}');
return;
}
console.info('unlockScreen callback success');
});
```
## screenlock.unlockScreen
unlockScreen(): Promise<void>
解锁屏幕,使用Promise作为异步方法。
**系统能力**: SystemCapability.MiscServices.ScreenLock
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise<void> | 以Promise形式返回结果。 |
- 示例:
```
screenlock.unlockScreen().then(() => {
console.log('unlockScreen success');
}).catch((err) => {
console.error('unlockScreen fail, promise: err->${JSON.stringify(err)}');
});
```
......@@ -6,6 +6,7 @@
## 导入模块
```
import systemTime from '@ohos.systemTime';
```
......@@ -15,15 +16,20 @@ import systemTime from '@ohos.systemTime';
setTime(time : number, callback : AsyncCallback<void>) : void
设置系统时间,需要ohos.permission.SET_TIME权限。
设置系统时间。
**需要权限:**ohos.permission.SET_TIME
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| time | number | 是 | 目标时间戳(毫秒)。 |
| callback | AsyncCallback<void> | 是 | 回调函数,可以在回调函数中处理接口返回值。 |
| time | number | 是 | 目标时间戳(毫秒)。 |
| callback | AsyncCallback<void> | 是 | 回调函数,可以在回调函数中处理接口返回值。 |
- 示例:
```
// time对应的时间为2021-01-20 02:36:25
var time = 1611081385000;
......@@ -32,7 +38,7 @@ setTime(time : number, callback : AsyncCallback<void>) : void
console.error(`failed to systemTime.setTime because ` + JSON.stringify(error));
return;
}
console.log(`success to systemTime.setTime: ` + JSON.stringify(data));
console.log(`systemTime.setTime success data : ` + JSON.stringify(data));
});
```
......@@ -41,51 +47,229 @@ setTime(time : number, callback : AsyncCallback<void>) : void
setTime(time : number) : Promise<void>
设置系统时间,需要ohos.permission.SET_TIME权限。
设置系统时间。
**需要权限:**ohos.permission.SET_TIME
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| time | number | 是 | 目标时间戳(毫秒)。 |
| time | number | 是 | 目标时间戳(毫秒)。 |
- 返回值:
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| Promise<void> | 返回的异步回调函数。 |
| Promise<void> | 返回的异步回调函数。 |
- 示例:
```
// time对应的时间为2021-01-20 02:36:25
var time = 1611081385000;
systemTime.setTime(time).then((data) => {
console.log(`success to systemTime.setTime: ` + JSON.stringify(data));
console.log(`systemTime.setTime success data : ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to systemTime.setTime because ` + JSON.stringify(error));
});
```
## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(isNano?: boolean, callback: AsyncCallback&lt;number&gt;): void
获取自 Unix 纪元以来经过的时间,使用callback形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| isNano | boolean | 否 | 如果是true,返回纳秒数;否则返回毫秒数。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自&nbsp;Unix&nbsp;纪元以来经过的时间。 |
- 示例:
```
systemTime.getCurrentTime(true, (error, data) => {
if (error) {
console.error(`failed to systemTime.getCurrentTime because ` + JSON.stringify(error));
return;
}
console.log(`systemTime.getCurrentTime success data : ` + JSON.stringify(data));
});
```
## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(isNano?: boolean): Promise&lt;number&gt;
获取自 Unix 纪元以来经过的时间,使用Promise形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| isNano | boolean | 否 | 如果是true,返回纳秒数;否则返回毫秒数。 |
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;number&gt; | 以Promise形式返回结果,返回自&nbsp;Unix&nbsp;纪元以来经过的时间。 |
- 示例:
```
systemTime.getCurrentTime().then((data) => {
console.log(`systemTime.getCurrentTime success data : ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to systemTime.getCurrentTime because ` + JSON.stringify(error));
});
```
## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(isNano?: boolean, callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| isNano | boolean | 否 | 如果是true,返回纳秒数;否则返回毫秒数。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来但不包括度睡眠时间经过的时间。 |
- 示例:
```
systemTime.getRealActiveTime(true, (error, data) => {
if (error) {
console.error(`failed to systemTime.getRealActiveTimebecause ` + JSON.stringify(error));
return;
}
console.log(`systemTime.getRealActiveTime success data : ` + JSON.stringify(data));
});
```
## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(isNano?: boolean): Promise&lt;number&gt;
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用Promise形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| isNano | boolean | 否 | 如果是true,返回纳秒数;否则返回毫秒数。 |
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;number&gt; | 以Promise形式返回结果,返回自系统启动以来但不包括度睡眠时间经过的时间。 |
- 示例:
```
systemTime.getCurrentTime().then((data) => {
console.log(`systemTime.getRealActiveTime success data : ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to systemTime.getRealActiveTime because ` + JSON.stringify(error));
});
```
## systemTime.getRealTime<sup>8+</sup>
getRealTime(callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| isNano | boolean | 否 | 如果是true,返回纳秒数;否则返回毫秒数。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来包括深度睡眠时间经过的毫秒数。 |
- 示例:
```
systemTime.getRealTime(true, (error, data) => {
if (error) {
console.error(`failed to systemTime.getRealTime because ` + JSON.stringify(error));
return;
}
console.log(`systemTime.getRealTime success data: ` + JSON.stringify(data));
});
```
## systemTime.getRealTime<sup>8+</sup>
getRealTime(): Promise&lt;number&gt;
获取自系统启动以来经过的时间,包括深度睡眠时间,使用Promise形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| isNano | boolean | 否 | 如果是true,返回纳秒数;否则返回毫秒数。 |
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;number&gt; | 以Promise形式返回结果,返回自系统启动以来包括深度睡眠时间经过的时间。 |
- 示例:
```
systemTime.getRealTime().then((data) => {
console.log(`systemTime.getRealTime success data: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to systemTime.getRealTime because ` + JSON.stringify(error));
});
```
## systemTime.setDate
setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
设置系统日期,需要ohos.permission.SET_TIME权限。
设置系统日期,使用callback形式返回结果。
**需要权限:**ohos.permission.SET_TIME
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| date | Date | 是 | 目标日期。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,可以在回调函数中处理接口返回值。 |
| date | Date | 是 | 目标日期。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,可以在回调函数中处理接口返回值。 |
- 示例:
```
var data = new Date("October 13, 2020 11:13:00");
systemTime.setDate(data,(error, data) => {
if (error) {
console.error('SystemTimePlugin setDate failed because ' + JSON.stringify(error));
console.error('failed to systemTime.setDate because ' + JSON.stringify(error));
return;
}
console.info('SystemTimePlugin setDate success data : ' + JSON.stringify(data));
console.info('systemTime.setDate success data : ' + JSON.stringify(data));
});
```
......@@ -94,25 +278,80 @@ setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
setDate(date: Date): Promise&lt;void&gt;
设置系统日期,需要ohos.permission.SET_TIME权限。
设置系统日期,使用Promise形式返回结果。
**需要权限:**ohos.permission.SET_TIME
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| date | Date | 是 | 目标日期。 |
| date | Date | 是 | 目标日期。 |
- 返回值:
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 返回的异步回调函数。 |
| Promise&lt;void&gt; | 返回的异步回调函数。 |
- 示例:
```
var data = new Date("October 13, 2020 11:13:00");
systemTime.setDate(data).then((value) => {
console.log(`SystemTimePlugin success to systemTime.setDate: ` + JSON.stringify(value));
console.log(`systemTime.setDate success data : ` + JSON.stringify(value));
}).catch((error) => {
console.error(`SystemTimePlugin failed to systemTime.setDate because: ` + JSON.stringify(error));
console.error(`failed to systemTime.setDate because: ` + JSON.stringify(error));
});
```
## systemTime.getDate<sup>8+</sup>
getDate(callback: AsyncCallback&lt;Date&gt;): void
获取当前系统日期,使用callback形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Date&gt; | 是 | 回调函数,返回当前系统日期。 |
- 示例:
```
systemTime.getDate((error, data) => {
if (error) {
console.error(`failed to systemTime.getDate because ` + JSON.stringify(error));
return;
}
console.log(`systemTime.getDate success data : ` + JSON.stringify(data));
});
```
## systemTime.getDate<sup>8+</sup>
getDate(): Promise&lt;Date&gt;
获取当前系统日期,使用Promise形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;Date&gt; | 以Promise形式返回结果,返回当前系统日期。 |
- 示例:
```
systemTime.getDate().then((data) => {
console.log(`systemTime.getDate success data : ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to systemTime.getDate because ` + JSON.stringify(error));
});
```
......@@ -121,22 +360,27 @@ setDate(date: Date): Promise&lt;void&gt;
setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void
设置系统时区,需要ohos.permission.SET_TIME_ZONE权限。
设置系统时区。
**需要权限:**ohos.permission.SET_TIME_ZONE
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| timezone | string | 是 | 系统时区。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,可以在回调函数中处理接口返回值。 |
| timezone | string | 是 | 系统时区。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,可以在回调函数中处理接口返回值。 |
- 示例:
```
systemTime.setTimezone('Asia/Shanghai', (error, data) => {
if (error) {
console.error('SystemTimePlugin setTimezone failed because ' + JSON.stringify(error));
console.error('failed to systemTime.setTimezone because ' + JSON.stringify(error));
return;
}
console.info('SystemTimePlugin setTimezone success data : ' + JSON.stringify(data));
console.info('SystemTimePlugin systemTime.setTimezone success data : ' + JSON.stringify(data));
});
```
......@@ -145,23 +389,78 @@ setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void
setTimezone(timezone: string): Promise&lt;void&gt;
设置系统时区,需要ohos.permission.SET_TIME_ZONE权限。
设置系统时区。
**需要权限:**ohos.permission.SET_TIME_ZONE
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| timezone | string | 是 | 系统时区。 |
| timezone | string | 是 | 系统时区。 |
- 返回值:
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 返回的异步回调函数。 |
| Promise&lt;void&gt; | 返回的异步回调函数。 |
- 示例:
```
systemTime.setTimezone('Asia/Shanghai').then((data) => {
console.log(`SystemTimePlugin success to systemTime.setTimezone: ` + JSON.stringify(data));
console.log(`systemTime.setTimezone success data : ` + JSON.stringify(data));
}).catch((error) => {
console.error(`SystemTimePlugin failed to systemTime.setTimezone because: ` + JSON.stringify(error));
console.error(`failed to systemTime.setTimezone because: ` + JSON.stringify(error));
});
```
## systemTime.getTimeZone<sup>8+</sup>
getTimeZone(callback: AsyncCallback&lt;string&gt;): void
获取系统时区,使用callback形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数,返回系统时区。 |
- 示例:
```
systemTime.getTimeZone((error, data) => {
if (error) {
console.error(`failed to systemTime.getTimeZone because ` + JSON.stringify(error));
return;
}
console.log(`systemTime.getTimeZone success data : ` + JSON.stringify(data));
});
```
## systemTime.getTimeZone<sup>8+</sup>
getTimeZone(): Promise&lt;string&gt;
获取系统时区,使用Promise形式返回结果。
**系统能力**: SystemCapability.Miscservices.Time
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;string&gt; | 以Promise形式返回结果,返回系统时区。 |
- 示例:
```
systemTime.getDate().then((data) => {
console.log(`systemTime.getTimeZone success data : ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to systemTime.getTimeZone because ` + JSON.stringify(error));
});
```
# 壁纸
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```
import wallpaper from '@ohos.wallpaper';
```
## WallpaperType
定义壁纸类型。
**系统能力**: 以下各项对应的系统能力均为SystemCapability.Miscservices.Wallpaper。
| 名称 | 说明 |
| -------- | -------- |
| WALLPAPER_LOCKSCREEN | 锁屏壁纸标识。 |
| WALLPAPER_SYSTEM | 主屏幕壁纸标识。 |
## wallpaper.getColors
getColors(wallpaperType: WallpaperType, callback: AsyncCallback&lt;Array&lt;RgbaColor&gt;&gt;): void
获取指定类型壁纸的主要颜色信息。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
| callback | AsyncCallback&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | 是 | 回调函数,返回壁纸的主要颜色信息。 |
- 示例:
```
wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to getColors because: ` + JSON.stringify(error));
return;
}
console.log(`success to getColors.`);
});
```
## wallpaper.getColors
getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;
获取指定类型壁纸的主要颜色信息。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | 返回壁纸的主要颜色信息。 |
- 示例:
```
wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to getColors.`);
}).catch((error) => {
console.error(`failed to getColors because: ` + JSON.stringify(error));
});
```
## wallpaper.getId
getId(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void
获取指定类型壁纸的ID。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回壁纸的ID。如果配置了指定类型的壁纸就返回一个大于等于0的数,否则返回-1。取值范围是-1~2^31-1。 |
- 示例:
```
wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to getId because: ` + JSON.stringify(error));
return;
}
console.log(`success to getId: ` + JSON.stringify(data));
});
```
## wallpaper.getId
getId(wallpaperType: WallpaperType): Promise&lt;number&gt;
获取指定类型壁纸的ID。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;number&gt; | 壁纸的ID。如果配置了这种壁纸类型的壁纸就返回一个大于等于0的数,否则返回-1。取值范围是-1~2^31-1。 |
- 示例:
```
wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to getId: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to getId because: ` + JSON.stringify(error));
});
```
## wallpaper.getMinHeight
getMinHeight(callback: AsyncCallback&lt;number&gt;): void
获取壁纸的最小高度值。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 |
- 示例:
```
wallpaper.getMinHeight((error, data) => {
if (error) {
console.error(`failed to getMinHeight because: ` + JSON.stringify(error));
return;
}
console.log(`success to getMinHeight: ` + JSON.stringify(data));
});
```
## wallpaper.getMinHeight
getMinHeight(): Promise&lt;number&gt;
获取壁纸的最小高度值。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;number&gt; | 返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 |
- 示例:
```
wallpaper.getMinHeight().then((data) => {
console.log(`success to getMinHeight: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to getMinHeight because: ` + JSON.stringify(error));
});
```
## wallpaper.getMinWidth
getMinWidth(callback: AsyncCallback&lt;number&gt;): void
获取壁纸的最小宽度值。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 |
- 示例:
```
wallpaper.getMinWidth((error, data) => {
if (error) {
console.error(`failed to getMinWidth because: ` + JSON.stringify(error));
return;
}
console.log(`success to getMinWidth: ` + JSON.stringify(data));
});
```
## wallpaper.getMinWidth
getMinWidth(): Promise&lt;number&gt;
获取壁纸的最小宽度值。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;number&gt; | 壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 |
- 示例:
```
wallpaper.getMinWidth().then((data) => {
console.log(`success to getMinWidth: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to getMinWidth because: ` + JSON.stringify(error));
});
```
## wallpaper.isChangePermitted
isChangePermitted(callback: AsyncCallback&lt;boolean&gt;): void
是否允许应用改变当前用户的壁纸。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 |
- 示例:
```
wallpaper.isChangePermitted((error, data) => {
if (error) {
console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
return;
}
console.log(`success to isChangePermitted: ` + JSON.stringify(data));
});
```
## wallpaper.isChangePermitted
isChangePermitted(): Promise&lt;boolean&gt;
是否允许应用改变当前用户的壁纸。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 |
- 示例:
```
wallpaper.isChangePermitted().then((data) => {
console.log(`success to isChangePermitted: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
});
```
## wallpaper.isOperationAllowed
isOperationAllowed(callback: AsyncCallback&lt;boolean&gt;): void
是否允许用户设置壁纸。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,返回是否允许用户设置壁纸。如果允许返回true,否则返回false。 |
- 示例:
```
wallpaper.isOperationAllowed((error, data) => {
if (error) {
console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
return;
}
console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
});
```
## wallpaper.isOperationAllowed
isOperationAllowed(): Promise&lt;boolean&gt;
是否允许用户设置壁纸。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 异步回调函数,返回是否允许用户设置壁纸。如果允许返回true,否则返回false。 |
- 示例:
```
wallpaper.isOperationAllowed().then((data) => {
console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
});
```
## wallpaper.reset
reset(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
移除指定类型的壁纸,恢复为默认显示的壁纸。
**需要权限**:ohos.permission.SET_WALLPAPER
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,调用成功则返回是否移除成功的结果,调用失败则返回error信息。 |
- 示例:
```
wallpaper.reset((error, data) => {
if (error) {
console.error(`failed to reset because: ` + JSON.stringify(error));
return;
}
console.log(`success to reset.`);
});
```
## wallpaper.reset
reset(wallpaperType: WallpaperType): Promise&lt;void&gt;
移除指定类型的壁纸,恢复为默认显示的壁纸。
**需要权限:**ohos.permission.SET_WALLPAPER
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 调用成功则返回是否移除成功的结果,调用失败则返回error信息。 |
- 示例:
```
wallpaper.reset(wallpaper.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to reset.`);
}).catch((error) => {
console.error(`failed to reset because: ` + JSON.stringify(error));
});
```
## wallpaper.setWallpaper
setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
将指定资源设置为指定类型的壁纸。
**需要权限:** ohos.permission.SET_WALLPAPER
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| uriOrPixelMap | string&nbsp;\|&nbsp;[ERROR:Invalid&nbsp;link:zh-cn_topic_0000001154665636.xml#xref134981523104113,link:zh-cn_topic_0000001122977382.xml#section160331714124](zh-cn_topic_0000001122977382.xml#section160331714124) | 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,调用成功则返回是返回设置的结果,调用失败则返回error信息。 |
- 示例:
```
// uriOrPixelMap类型为string
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return;
}
console.log(`success to setWallpaper.`);
});
// uriOrPixelMap类型为image.PixelMap
import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = {
"desiredSize": {
"height": 3648,
"width": 2736
}
};
imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WALLPAPER_SYSTEM, (error, data) => {
if (error) {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
return;
}
console.log(`success to setWallpaper.`);
});
}).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
});
```
## wallpaper.setWallpaper
setWallpaper(uriOrPixelMap: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;
将指定资源设置为指定类型的壁纸。
**需要权限**:ohos.permission.SET_WALLPAPER
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| uriOrPixelMap | string&nbsp;\|&nbsp;[ERROR:Invalid&nbsp;link:zh-cn_topic_0000001154665636.xml#xref2071734616,link:zh-cn_topic_0000001122977382.xml#section160331714124](zh-cn_topic_0000001122977382.xml#section160331714124) | 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 调用成功则返回是返回设置的结果,调用失败则返回error信息。 |
- 示例:
```
// uriOrPixelMap类型为string
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`);
}).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
});
// uriOrPixelMap类型为image.PixelMap
import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = {
"desiredSize": {
"height": 3648,
"width": 2736
}
};
imageSource.createPixelMap(opts).then((pixelMap) => {
wallpaper.setWallpaper(pixelMap, wallpaper.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`);
}).catch((error) => {
console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
});
}).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
});
```
## wallpaper.on('colorChange')
on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
订阅壁纸颜色变化结果上报事件。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 取值为'colorChange',表示壁纸颜色变化结果上报事件。 |
| callback | function | 是 | 壁纸颜色变化触发该回调方法,返回壁纸类型和壁纸的主要颜色信息。<br/>-&nbsp;colors<br/>&nbsp;&nbsp;壁纸的主要颜色信息,其类型见[RgbaColor](#rgbacolor)。<br/>-&nbsp;wallpaperType<br/>&nbsp;&nbsp;壁纸类型。 |
- 示例:
```
let listener = (colors, wallpaperType) => {
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange', listener);
```
## wallpaper.off('colorChange')
off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
取消订阅壁纸颜色变化结果上报事件。
**系统能力**: SystemCapability.Miscservices.Wallpaper
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 取值为'colorChange',表示取消订阅壁纸颜色变化结果上报事件。 |
| callback | function | 否 | &nbsp;&nbsp;表示取消壁纸颜色变化结果上报,不填写该参数则取消订阅该type对应的所有回调。<br/>-&nbsp;colors<br/>&nbsp;&nbsp;壁纸的主要颜色信息,其类型见[RgbaColor](#rgbacolor)。<br/>-&nbsp;wallpaperType<br/>&nbsp;&nbsp;壁纸类型。 |
- 示例:
```
let listener = (colors, wallpaperType) => {
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange', listener);
// 取消订阅listener
wallpaper.off('colorChange', listener);
// 取消所有'colorChange'类型的订阅
wallpaper.off('colorChange');
```
## RgbaColor
**系统能力**: 以下各项对应的系统能力均为SystemCapability.Miscservices.Wallpaper。
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| red | number | 是 | 是 | 表示红色值,范围为&nbsp;0&nbsp;&nbsp;255。 |
| green | number | 是 | 是 | 表示绿色值,范围为&nbsp;0&nbsp;&nbsp;255。 |
| blue | number | 是 | 是 | 表示蓝色值,范围为&nbsp;0&nbsp;&nbsp;255。 |
| alpha | number | 是 | 是 | 表示&nbsp;alpha&nbsp;值,范围为&nbsp;0&nbsp;&nbsp;255。 |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册