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

!13555 资料需求回合

Merge pull request !13555 from wTong888/cherry-pick-1673572732
......@@ -20,12 +20,12 @@ import systemTimer from '@ohos.systemTimer';
**系统能力:** SystemCapability.MiscServices.Time
| 名称 | 类型 | 值 | 说明 |
| ------------------- | ------ | ---- | ---------------------------- |
| TIMER_TYPE_REALTIME | number | 1 | 系统启动时间定时器。(定时器启动时间不能晚于当前设置的系统时间) |
| TIMER_TYPE_WAKEUP | number | 2 | 唤醒定时器。 |
| TIMER_TYPE_EXACT | number | 4 | 精准定时器。 |
| TIMER_TYPE_IDLE | number | 8 | IDLE模式定时器(暂不支持)。 |
| 名称 | 类型 | 值 | 说明 |
| ------------------- | ------ | ---- | ------------------------------------------------------------ |
| TIMER_TYPE_REALTIME | number | 1 | 系统启动时间定时器。(定时器启动时间不能晚于当前设置的系统时间) |
| TIMER_TYPE_WAKEUP | number | 2 | 唤醒定时器。 |
| TIMER_TYPE_EXACT | number | 4 | 精准定时器。 |
| TIMER_TYPE_IDLE | number | 8 | IDLE模式定时器(暂不支持)。 |
## TimerOptions
......@@ -33,13 +33,13 @@ import systemTimer from '@ohos.systemTimer';
**系统能力:** SystemCapability.MiscServices.Time
| 名称 | 类型 | 必填 | 说明 |
| --------- | --------------------------------- | ---- | ------------------------------------------------------------ |
| type | number | 是 | 定时器类型。<br>取值为1时,表示为系统启动时间定时器(定时器启动时间不能晚于当前设置的系统时间) ;<br>取值为2时,表示为唤醒定时器;<br>取值为4时,表示为精准定时器;<br>取值为5时,表示为IDLE模式定时器(暂不支持)。 |
| repeat | boolean | 是 | true为循环定时器,false为单次定时器。 |
| interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | 否 | 设置通知的WantAgent,定时器到期后通知。(支持拉起应用MainAbility,暂不支持拉起ServiceAbility。) |
| callback | number | 是 | 以回调函数的形式返回定时器的ID。 |
| 名称 | 类型 | 必填 | 说明 |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | number | 是 | 定时器类型。<br>取值为1,表示为系统启动时间定时器(定时器启动时间不能晚于当前设置的系统时间) ;<br>取值为2,表示为唤醒定时器;<br>取值为4,表示为精准定时器;<br>取值为8,表示为IDLE模式定时器(暂不支持)。 |
| repeat | boolean | 是 | true为循环定时器,false为单次定时器。 |
| interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 |
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | 否 | 设置通知的WantAgent,定时器到期后通知。(支持拉起应用MainAbility,暂不支持拉起ServiceAbility。) |
| callback | number | 是 | 以回调函数的形式返回定时器的ID。 |
## systemTimer.createTimer
......@@ -61,19 +61,23 @@ createTimer(options: TimerOptions, callback: AsyncCallback&lt;number&gt;): void
```js
export default {
systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat: false
};
systemTimer.createTimer(options, (error, data) => {
if (error) {
console.error(`Failed to create timer. Cause:` + JSON.stringify(error));
return;
}
console.log(`Succeeded in creating timer. Data:` + JSON.stringify(data));
});
systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat: false
};
try {
systemTimer.createTimer(options, (error, timerId) => {
if (error) {
console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in creating timer. timerId: ${timerId}`);
});
} catch(e) {
console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -101,17 +105,21 @@ createTimer(options: TimerOptions): Promise&lt;number&gt;
```js
export default {
systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
};
systemTimer.createTimer(options).then((data) => {
console.log(`Succeeded in creating timer. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to create timer. Cause:` + JSON.stringify(error));
});
systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
};
try {
systemTimer.createTimer(options).then((timerId) => {
console.info(`Succeeded in creating timer. timerId: ${timerId}`);
}).catch((error) => {
console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -135,21 +143,26 @@ startTimer(timer: number, triggerTime: number, callback: AsyncCallback&lt;void&g
```js
export default {
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
try {
systemTimer.startTimer(timerId, triggerTime, (error) => {
if (error) {
console.error(`Failed to start timer. Cause:` + JSON.stringify(error));
return;
}
if (error) {
console.info(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in starting timer.`);
});
} catch(e) {
console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -178,20 +191,24 @@ startTimer(timer: number, triggerTime: number): Promise&lt;void&gt;
```js
export default {
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime).then((data) => {
console.log(`Succeeded in startting timer. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to start timer. Cause:` + JSON.stringify(error));
});
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
try {
systemTimer.startTimer(timerId, triggerTime).then(() => {
console.info(`Succeeded in starting timer.`);
}).catch((error) => {
console.info(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -215,20 +232,25 @@ stopTimer(timer: number, callback: AsyncCallback&lt;void&gt;): void
```js
export default {
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime);
try {
systemTimer.stopTimer(timerId, (error) => {
if (error) {
console.error(`Failed to stop timer. Cause:` + JSON.stringify(error));
return;
}
if (error) {
console.info(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in stopping timer.`);
});
} catch(e) {
console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -258,19 +280,23 @@ stopTimer(timer: number): Promise&lt;void&gt;
```js
export default {
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
systemTimer.stopTimer(timerId).then((data) => {
console.log(`Succeeded in stopping timer. Data:` + JSON.stringify(data));
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime);
try {
systemTimer.stopTimer(timerId).then(() => {
console.info(`Succeeded in stopping timer.`);
}).catch((error) => {
console.error(`Failed to stop timer. Cause:` + JSON.stringify(error));
console.info(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -294,23 +320,28 @@ destroyTimer(timer: number, callback: AsyncCallback&lt;void&gt;): void
```js
export default {
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
async systemTimer () {
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime);
systemTimer.stopTimer(timerId);
try {
systemTimer.destroyTimer(timerId, (error) => {
if (error) {
console.info(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
return;
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
systemTimer.stopTimer(timerId)
systemTimer.destroyTimer(timerId, (error) => {
if (error) {
console.error(`Failed to destroy timer. Cause:` + JSON.stringify(error));
return;
}
});
console.info(`Succeeded in destroying timer.`);
});
} catch(e) {
console.info(`Failed to destroying timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -338,21 +369,25 @@ destroyTimer(timer: number): Promise&lt;void&gt;
```js
export default {
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
systemTimer.stopTimer(timerId)
systemTimer.destroyTimer(timerId).then((data) => {
console.log(`Succeeded in destroying timer. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to destroy timer. Cause:` + JSON.stringify(error));
});
async systemTimer (){
let options = {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime);
systemTimer.stopTimer(timerId);
try {
systemTimer.destroyTimer(timerId).then(() => {
console.info(`Succeeded in destroying timer.`);
}).catch((error) => {
console.info(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
console.info(`Failed to destroying timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
\ No newline at end of file
# 时间时区服务错误码
## -1 锁屏服务异常
**错误信息**
The parameter check failed or permission denied or system error.
**错误描述**
参数校验失败、权限校验失败或者时间时区服务异常。
**可能原因**
该错误码代表一种通用错误码,可根据错误信息判断具体异常,可能原因如下:
1. 参数校验失败,传入参数无效。
2. 权限校验失败,权限未配置。应用设置时间未配置ohos.permission.SET_TIME或者设置时区未配置ohos.permission.SET_TIME_ZONE。
3. 系统运行异常。内存申请、多线程处理等内核通用错误。
**处理步骤**
1. 参数校验失败,传入参数无效。检查参数是否按照要求传入。
2. 权限校验失败,应用设置时间配置ohos.permission.SET_TIME或者设置时区配置ohos.permission.SET_TIME_ZONE。
3. 系统运行异常。确认内存是否足够。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册