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

!13555 资料需求回合

Merge pull request !13555 from wTong888/cherry-pick-1673572732
...@@ -21,7 +21,7 @@ import systemTimer from '@ohos.systemTimer'; ...@@ -21,7 +21,7 @@ import systemTimer from '@ohos.systemTimer';
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
| 名称 | 类型 | 值 | 说明 | | 名称 | 类型 | 值 | 说明 |
| ------------------- | ------ | ---- | ---------------------------- | | ------------------- | ------ | ---- | ------------------------------------------------------------ |
| TIMER_TYPE_REALTIME | number | 1 | 系统启动时间定时器。(定时器启动时间不能晚于当前设置的系统时间) | | TIMER_TYPE_REALTIME | number | 1 | 系统启动时间定时器。(定时器启动时间不能晚于当前设置的系统时间) |
| TIMER_TYPE_WAKEUP | number | 2 | 唤醒定时器。 | | TIMER_TYPE_WAKEUP | number | 2 | 唤醒定时器。 |
| TIMER_TYPE_EXACT | number | 4 | 精准定时器。 | | TIMER_TYPE_EXACT | number | 4 | 精准定时器。 |
...@@ -34,11 +34,11 @@ import systemTimer from '@ohos.systemTimer'; ...@@ -34,11 +34,11 @@ import systemTimer from '@ohos.systemTimer';
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | --------------------------------- | ---- | ------------------------------------------------------------ | | --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | number | 是 | 定时器类型。<br>取值为1时,表示为系统启动时间定时器(定时器启动时间不能晚于当前设置的系统时间) ;<br>取值为2时,表示为唤醒定时器;<br>取值为4时,表示为精准定时器;<br>取值为5时,表示为IDLE模式定时器(暂不支持)。 | | type | number | 是 | 定时器类型。<br>取值为1,表示为系统启动时间定时器(定时器启动时间不能晚于当前设置的系统时间) ;<br>取值为2,表示为唤醒定时器;<br>取值为4,表示为精准定时器;<br>取值为8,表示为IDLE模式定时器(暂不支持)。 |
| repeat | boolean | 是 | true为循环定时器,false为单次定时器。 | | repeat | boolean | 是 | true为循环定时器,false为单次定时器。 |
| interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 | | interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | 否 | 设置通知的WantAgent,定时器到期后通知。(支持拉起应用MainAbility,暂不支持拉起ServiceAbility。) | | wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | 否 | 设置通知的WantAgent,定时器到期后通知。(支持拉起应用MainAbility,暂不支持拉起ServiceAbility。) |
| callback | number | 是 | 以回调函数的形式返回定时器的ID。 | | callback | number | 是 | 以回调函数的形式返回定时器的ID。 |
...@@ -66,13 +66,17 @@ export default { ...@@ -66,13 +66,17 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat: false repeat: false
}; };
systemTimer.createTimer(options, (error, data) => { try {
systemTimer.createTimer(options, (error, timerId) => {
if (error) { if (error) {
console.error(`Failed to create timer. Cause:` + JSON.stringify(error)); console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.log(`Succeeded in creating timer. Data:` + JSON.stringify(data)); console.info(`Succeeded in creating timer. timerId: ${timerId}`);
}); });
} catch(e) {
console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
}
} }
} }
``` ```
...@@ -106,11 +110,15 @@ export default { ...@@ -106,11 +110,15 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
}; };
systemTimer.createTimer(options).then((data) => { try {
console.log(`Succeeded in creating timer. Data:` + JSON.stringify(data)); systemTimer.createTimer(options).then((timerId) => {
console.info(`Succeeded in creating timer. timerId: ${timerId}`);
}).catch((error) => { }).catch((error) => {
console.error(`Failed to create timer. Cause:` + JSON.stringify(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}`);
}
} }
} }
``` ```
...@@ -140,15 +148,20 @@ export default { ...@@ -140,15 +148,20 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = await systemTimer.createTimer(options) let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime() let triggerTime = new Date().getTime();
triggerTime += 3000 triggerTime += 3000;
try {
systemTimer.startTimer(timerId, triggerTime, (error) => { systemTimer.startTimer(timerId, triggerTime, (error) => {
if (error) { if (error) {
console.error(`Failed to start timer. Cause:` + JSON.stringify(error)); console.info(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in starting timer.`);
}); });
} catch(e) {
console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
}
} }
} }
``` ```
...@@ -183,14 +196,18 @@ export default { ...@@ -183,14 +196,18 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = await systemTimer.createTimer(options) let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime() let triggerTime = new Date().getTime();
triggerTime += 3000 triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime).then((data) => { try {
console.log(`Succeeded in startting timer. Data:` + JSON.stringify(data)); systemTimer.startTimer(timerId, triggerTime).then(() => {
console.info(`Succeeded in starting timer.`);
}).catch((error) => { }).catch((error) => {
console.error(`Failed to start timer. Cause:` + JSON.stringify(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}`);
}
} }
} }
``` ```
...@@ -219,16 +236,21 @@ export default { ...@@ -219,16 +236,21 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = await systemTimer.createTimer(options) let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime() let triggerTime = new Date().getTime();
triggerTime += 3000 triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime) systemTimer.startTimer(timerId, triggerTime);
try {
systemTimer.stopTimer(timerId, (error) => { systemTimer.stopTimer(timerId, (error) => {
if (error) { if (error) {
console.error(`Failed to stop timer. Cause:` + JSON.stringify(error)); console.info(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in stopping timer.`);
}); });
} catch(e) {
console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
}
} }
} }
``` ```
...@@ -262,15 +284,19 @@ export default { ...@@ -262,15 +284,19 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = await systemTimer.createTimer(options) let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime() let triggerTime = new Date().getTime();
triggerTime += 3000 triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime) systemTimer.startTimer(timerId, triggerTime);
systemTimer.stopTimer(timerId).then((data) => { try {
console.log(`Succeeded in stopping timer. Data:` + JSON.stringify(data)); systemTimer.stopTimer(timerId).then(() => {
console.info(`Succeeded in stopping timer.`);
}).catch((error) => { }).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}`);
}
} }
} }
``` ```
...@@ -299,17 +325,22 @@ export default { ...@@ -299,17 +325,22 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = await systemTimer.createTimer(options) let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime() let triggerTime = new Date().getTime();
triggerTime += 3000 triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime) systemTimer.startTimer(timerId, triggerTime);
systemTimer.stopTimer(timerId) systemTimer.stopTimer(timerId);
try {
systemTimer.destroyTimer(timerId, (error) => { systemTimer.destroyTimer(timerId, (error) => {
if (error) { if (error) {
console.error(`Failed to destroy timer. Cause:` + JSON.stringify(error)); console.info(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in destroying timer.`);
}); });
} catch(e) {
console.info(`Failed to destroying timer. message: ${e.message}, code: ${e.code}`);
}
} }
} }
``` ```
...@@ -343,16 +374,20 @@ export default { ...@@ -343,16 +374,20 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = await systemTimer.createTimer(options) let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime() let triggerTime = new Date().getTime();
triggerTime += 3000 triggerTime += 3000;
systemTimer.startTimer(timerId, triggerTime) systemTimer.startTimer(timerId, triggerTime);
systemTimer.stopTimer(timerId) systemTimer.stopTimer(timerId);
systemTimer.destroyTimer(timerId).then((data) => { try {
console.log(`Succeeded in destroying timer. Data:` + JSON.stringify(data)); systemTimer.destroyTimer(timerId).then(() => {
console.info(`Succeeded in destroying timer.`);
}).catch((error) => { }).catch((error) => {
console.error(`Failed to destroy timer. Cause:` + JSON.stringify(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.
先完成此消息的编辑!
想要评论请 注册