Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
90773e5a
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
90773e5a
编写于
9月 06, 2023
作者:
O
openharmony_ci
提交者:
Gitee
9月 06, 2023
浏览文件
操作
浏览文件
下载
差异文件
!24086 元能力及事件通知ArkTs整改
Merge pull request !24086 from xuzhihao/master
上级
f400f307
352614bd
变更
31
展开全部
隐藏空白更改
内联
并排
Showing
31 changed file
with
2052 addition
and
1345 deletion
+2052
-1345
zh-cn/application-dev/application-models/arkts-ui-widget-event-call.md
...tion-dev/application-models/arkts-ui-widget-event-call.md
+36
-15
zh-cn/application-dev/application-models/arkts-ui-widget-event-formextensionability.md
...tion-models/arkts-ui-widget-event-formextensionability.md
+4
-4
zh-cn/application-dev/application-models/arkts-ui-widget-event-router.md
...on-dev/application-models/arkts-ui-widget-event-router.md
+15
-12
zh-cn/application-dev/application-models/arkts-ui-widget-event-uiability.md
...dev/application-models/arkts-ui-widget-event-uiability.md
+57
-28
zh-cn/application-dev/application-models/arkts-ui-widget-image-update.md
...on-dev/application-models/arkts-ui-widget-image-update.md
+84
-81
zh-cn/application-dev/application-models/arkts-ui-widget-lifecycle.md
...ation-dev/application-models/arkts-ui-widget-lifecycle.md
+64
-66
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-proxy.md
...dev/application-models/arkts-ui-widget-update-by-proxy.md
+45
-37
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-status.md
...ev/application-models/arkts-ui-widget-update-by-status.md
+40
-34
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-time.md
...-dev/application-models/arkts-ui-widget-update-by-time.md
+4
-3
zh-cn/application-dev/application-models/common-event-publish.md
...pplication-dev/application-models/common-event-publish.md
+7
-5
zh-cn/application-dev/application-models/common-event-remove-sticky.md
...tion-dev/application-models/common-event-remove-sticky.md
+2
-1
zh-cn/application-dev/application-models/common-event-static-subscription.md
...ev/application-models/common-event-static-subscription.md
+3
-2
zh-cn/application-dev/application-models/common-event-subscription.md
...ation-dev/application-models/common-event-subscription.md
+5
-4
zh-cn/application-dev/application-models/common-event-unsubscription.md
...ion-dev/application-models/common-event-unsubscription.md
+2
-1
zh-cn/application-dev/reference/apis/js-apis-app-form-formBindingData.md
...on-dev/reference/apis/js-apis-app-form-formBindingData.md
+6
-5
zh-cn/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md
...v/reference/apis/js-apis-app-form-formExtensionAbility.md
+21
-23
zh-cn/application-dev/reference/apis/js-apis-app-form-formHost.md
...plication-dev/reference/apis/js-apis-app-form-formHost.md
+39
-39
zh-cn/application-dev/reference/apis/js-apis-app-form-formProvider.md
...ation-dev/reference/apis/js-apis-app-form-formProvider.md
+28
-43
zh-cn/application-dev/reference/apis/js-apis-application-formBindingData.md
...dev/reference/apis/js-apis-application-formBindingData.md
+2
-1
zh-cn/application-dev/reference/apis/js-apis-application-formHost.md
...cation-dev/reference/apis/js-apis-application-formHost.md
+3
-3
zh-cn/application-dev/reference/apis/js-apis-application-formProvider.md
...on-dev/reference/apis/js-apis-application-formProvider.md
+9
-19
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
+22
-2
zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md
...lication-dev/reference/apis/js-apis-commonEventManager.md
+26
-1
zh-cn/application-dev/reference/apis/js-apis-emitter.md
zh-cn/application-dev/reference/apis/js-apis-emitter.md
+21
-24
zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md
...ce/apis/js-apis-inner-application-formExtensionContext.md
+4
-4
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationFlags.md
...ence/apis/js-apis-inner-notification-notificationFlags.md
+2
-0
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationSubscriber.md
...apis/js-apis-inner-notification-notificationSubscriber.md
+130
-116
zh-cn/application-dev/reference/apis/js-apis-notification.md
zh-cn/application-dev/reference/apis/js-apis-notification.md
+853
-571
zh-cn/application-dev/reference/apis/js-apis-notificationManager.md
...ication-dev/reference/apis/js-apis-notificationManager.md
+348
-73
zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md
...ation-dev/reference/apis/js-apis-notificationSubscribe.md
+168
-122
zh-cn/application-dev/reference/apis/js-apis-system-notification.md
...ication-dev/reference/apis/js-apis-system-notification.md
+2
-6
未找到文件。
zh-cn/application-dev/application-models/arkts-ui-widget-event-call.md
浏览文件 @
90773e5a
...
...
@@ -53,27 +53,48 @@
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
function
FunACall
(
data
)
{
// 获取call事件中传递的所有参数
console
.
info
(
'
FunACall param:
'
+
JSON
.
stringify
(
data
.
readString
()));
return
null
;
}
function
FunBCall
(
data
)
{
console
.
info
(
'
FunBCall param:
'
+
JSON
.
stringify
(
data
.
readString
()));
return
null
;
import
Base
from
'
@ohos.base
'
import
rpc
from
'
@ohos.rpc
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
AbilityConstant
from
'
@ohos.app.ability.AbilityConstant
'
;
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
}
marshalling
(
messageSequence
:
rpc
.
MessageSequence
):
boolean
{
messageSequence
.
writeInt
(
this
.
num
);
messageSequence
.
writeString
(
this
.
str
);
return
true
;
}
unmarshalling
(
messageSequence
:
rpc
.
MessageSequence
):
boolean
{
this
.
num
=
messageSequence
.
readInt
();
this
.
str
=
messageSequence
.
readString
();
return
true
;
}
}
export
default
class
CameraAbility
extends
UIAbility
{
// 如果UIAbility第一次启动,在收到call事件后会触发onCreate生命周期回调
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
try
{
// 监听call事件所需的方法
this
.
callee
.
on
(
'
funA
'
,
FunACall
);
this
.
callee
.
on
(
'
funB
'
,
FunBCall
);
this
.
callee
.
on
(
'
funA
'
,
(
data
:
rpc
.
MessageSequence
)
=>
{
// 获取call事件中传递的所有参数
console
.
info
(
'
FunACall param:
'
+
JSON
.
stringify
(
data
.
readString
()));
return
new
MyParcelable
(
1
,
'
aaa
'
);
});
this
.
callee
.
on
(
'
funB
'
,
(
data
:
rpc
.
MessageSequence
)
=>
{
// 获取call事件中传递的所有参数
console
.
info
(
'
FunACall param:
'
+
JSON
.
stringify
(
data
.
readString
()));
return
new
MyParcelable
(
2
,
'
bbb
'
);
});
}
catch
(
err
)
{
console
.
error
(
`Failed to register callee on. Cause:
${
JSON
.
stringify
(
err
)}
`
);
console
.
error
(
`Failed to register callee on. Cause:
${
JSON
.
stringify
(
err
as
Base
.
BusinessError
)}
`
);
}
}
...
...
@@ -85,7 +106,7 @@
this
.
callee
.
off
(
'
funA
'
);
this
.
callee
.
off
(
'
funB
'
);
}
catch
(
err
)
{
console
.
error
(
`Failed to register callee off. Cause:
${
JSON
.
stringify
(
err
)}
`
);
console
.
error
(
`Failed to register callee off. Cause:
${
JSON
.
stringify
(
err
as
Base
.
BusinessError
)}
`
);
}
}
};
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-event-formextensionability.md
浏览文件 @
90773e5a
...
...
@@ -52,10 +52,10 @@
let
formData
=
new
Map
<
Object
,
string
>
();
formData
.
set
(
'
title
'
,
'
Title Update.
'
);
// 和卡片布局中对应
formData
.
set
(
'
detail
'
,
'
Description update success.
'
);
// 和卡片布局中对应
let
formInfo
=
formBindingData
.
createFormBindingData
(
formData
)
formProvider
.
updateForm
(
formId
,
formInfo
).
then
((
data
)
=>
{
console
.
info
(
'
FormAbility updateForm success.
'
+
JSON
.
stringify
(
data
)
);
})
let
formInfo
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
(
formData
);
formProvider
.
updateForm
(
formId
,
formInfo
).
then
(()
=>
{
console
.
info
(
'
FormAbility updateForm success.
'
);
})
;
}
...
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-event-router.md
浏览文件 @
90773e5a
...
...
@@ -54,26 +54,29 @@
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
window
from
'
@ohos.window
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
;
import
AbilityConstant
from
'
@ohos.app.ability.AbilityConstant
'
;
let
selectPage
=
""
;
let
currentWindowStage
=
null
;
let
selectPage
:
string
=
""
;
let
currentWindowStage
:
window
.
WindowStage
|
null
=
null
;
export
default
class
EntryAbility
extends
UIAbility
{
// 如果UIAbility第一次启动,在收到Router事件后会触发onCreate生命周期回调
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
// 获取router事件中传递的targetPage参数
console
.
info
(
"
onCreate want:
"
+
JSON
.
stringify
(
want
));
if
(
want
.
parameters
.
params
!==
undefined
)
{
let
params
=
JSON
.
parse
(
want
.
parameters
.
params
);
if
(
want
.
parameters
?
.
params
!==
undefined
)
{
let
params
:
Record
<
string
,
string
>
=
JSON
.
parse
(
JSON
.
stringify
(
want
.
parameters
?.
params
)
);
console
.
info
(
"
onCreate router targetPage:
"
+
params
.
targetPage
);
selectPage
=
params
.
targetPage
;
}
}
// 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调
onNewWant
(
want
,
l
aunchParam
)
{
onNewWant
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
console
.
info
(
"
onNewWant want:
"
+
JSON
.
stringify
(
want
));
if
(
want
.
parameters
.
params
!==
undefined
)
{
let
params
=
JSON
.
parse
(
want
.
parameters
.
params
);
if
(
want
.
parameters
?
.
params
!==
undefined
)
{
let
params
:
Record
<
string
,
string
>
=
JSON
.
parse
(
JSON
.
stringify
(
want
.
parameters
?.
params
)
);
console
.
info
(
"
onNewWant router targetPage:
"
+
params
.
targetPage
);
selectPage
=
params
.
targetPage
;
}
...
...
@@ -81,9 +84,9 @@
this
.
onWindowStageCreate
(
currentWindowStage
);
}
}
onWindowStageCreate
(
windowStage
:
window
.
WindowStage
)
{
let
targetPage
;
let
targetPage
:
string
;
// 根据传递的targetPage不同,选择拉起不同的页面
switch
(
selectPage
)
{
case
'
funA
'
:
...
...
@@ -98,7 +101,7 @@
if
(
currentWindowStage
===
null
)
{
currentWindowStage
=
windowStage
;
}
windowStage
.
loadContent
(
targetPage
,
(
err
,
data
)
=>
{
windowStage
.
loadContent
(
targetPage
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
&&
err
.
code
)
{
console
.
info
(
'
Failed to load the content. Cause: %{public}s
'
,
JSON
.
stringify
(
err
));
return
;
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-event-uiability.md
浏览文件 @
90773e5a
...
...
@@ -44,30 +44,33 @@
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
import
AbilityConstant
from
'
@ohos.app.ability.AbilityConstant
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
export
default
class
EntryAbility
extends
UIAbility
{
// 如果UIAbility第一次启动,在收到Router事件后会触发onCreate生命周期回调
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
this
.
handleFormRouterEvent
(
want
);
}
// 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调
onNewWant
(
want
,
l
aunchParam
)
{
onNewWant
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
this
.
handleFormRouterEvent
(
want
);
}
handleFormRouterEvent
(
want
)
{
handleFormRouterEvent
(
want
:
Want
)
{
console
.
info
(
'
Want:
'
+
JSON
.
stringify
(
want
));
if
(
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
]
!==
undefined
)
{
let
curFormId
=
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
]
;
let
message
=
JSON
.
parse
(
want
.
parameters
.
params
).
detail
;
if
(
want
.
parameters
&&
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
]
!==
undefined
)
{
let
curFormId
=
JSON
.
stringify
(
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
])
;
let
message
:
string
=
JSON
.
parse
(
JSON
.
stringify
(
want
.
parameters
.
params
)
).
detail
;
console
.
info
(
`UpdateForm formId:
${
curFormId
}
, message:
${
message
}
`
);
let
formData
=
{
let
formData
:
Record
<
string
,
string
>
=
{
"
detail
"
:
message
+
'
: UIAbility.
'
,
// 和卡片布局中对应
};
let
formMsg
=
formBindingData
.
createFormBindingData
(
formData
)
formProvider
.
updateForm
(
curFormId
,
formMsg
).
then
((
data
)
=>
{
console
.
info
(
'
updateForm success.
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
updateForm failed:
'
+
JSON
.
stringify
(
error
));
})
}
...
...
@@ -83,18 +86,21 @@
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
want
)
{
let
formId
=
want
.
parameters
[
"
ohos.extra.param.key.form_identity
"
];
let
dataObj1
=
{
"
formId
"
:
formId
};
onAddForm
(
want
:
Want
)
{
let
dataObj1
:
Record
<
string
,
string
>
|
undefined
;
if
(
want
.
parameters
&&
want
.
parameters
[
"
ohos.extra.param.key.form_identity
"
]
!=
undefined
)
{
let
formId
:
string
=
JSON
.
parse
(
JSON
.
stringify
(
want
.
parameters
[
"
ohos.extra.param.key.form_identity
"
]));
dataObj1
=
{
"
formId
"
:
formId
};
}
let
obj1
=
formBindingData
.
createFormBindingData
(
dataObj1
);
return
obj1
;
}
...
...
};
```
...
...
@@ -138,40 +144,63 @@
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
import
rpc
from
'
@ohos.rpc
'
;
import
AbilityConstant
from
'
@ohos.app.ability.AbilityConstant
'
;
const
MSG_SEND_METHOD
:
string
=
'
funA
'
;
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
}
marshalling
(
messageSequence
:
rpc
.
MessageSequence
):
boolean
{
messageSequence
.
writeInt
(
this
.
num
);
messageSequence
.
writeString
(
this
.
str
);
return
true
;
}
unmarshalling
(
messageSequence
:
rpc
.
MessageSequence
):
boolean
{
this
.
num
=
messageSequence
.
readInt
();
this
.
str
=
messageSequence
.
readString
();
return
true
;
}
}
// 在收到call事件后会触发callee监听的方法
function
FunACall
(
data
)
{
let
FunACall
=
(
data
:
rpc
.
MessageSequence
)
=>
{
// 获取call事件中传递的所有参数
let
params
=
JSON
.
parse
(
data
.
readString
())
let
params
:
Record
<
string
,
string
>
=
JSON
.
parse
(
data
.
readString
())
if
(
params
.
formId
!==
undefined
)
{
let
curFormId
=
params
.
formId
;
let
message
=
params
.
detail
;
let
curFormId
:
string
=
params
.
formId
;
let
message
:
string
=
params
.
detail
;
console
.
info
(
`UpdateForm formId:
${
curFormId
}
, message:
${
message
}
`
);
let
formData
=
{
let
formData
:
Record
<
string
,
string
>
=
{
"
detail
"
:
message
};
let
formMsg
=
formBindingData
.
createFormBindingData
(
formData
)
let
formMsg
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
(
formData
);
formProvider
.
updateForm
(
curFormId
,
formMsg
).
then
((
data
)
=>
{
console
.
info
(
'
updateForm success.
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
updateForm failed:
'
+
JSON
.
stringify
(
error
));
})
}
return
n
ull
;
return
n
ew
MyParcelable
(
1
,
'
aaa
'
)
;
}
export
default
class
EntryAbility
extends
UIAbility
{
// 如果UIAbility第一次启动,call事件后会触发onCreate生命周期回调
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
console
.
info
(
'
Want:
'
+
JSON
.
stringify
(
want
));
try
{
// 监听call事件所需的方法
// 监听call事件所需的方法
this
.
callee
.
on
(
MSG_SEND_METHOD
,
FunACall
);
}
catch
(
error
)
{
console
.
info
(
`
${
MSG_SEND_METHOD
}
register failed with error
${
JSON
.
stringify
(
error
)}
`
)
console
.
info
(
`
${
MSG_SEND_METHOD
}
register failed with error
${
JSON
.
stringify
(
error
as
Base
.
BusinessError
)}
`
)
}
}
...
}
```
\ No newline at end of file
zh-cn/application-dev/application-models/arkts-ui-widget-image-update.md
浏览文件 @
90773e5a
...
...
@@ -14,31 +14,34 @@
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
request
from
'
@ohos.request
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
;
import
fileFs
from
'
@ohos.file.fs
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
...
// 在添加卡片时,打开一个本地图片并将图片内容传递给卡片页面显示
onAddForm
(
w
ant
)
{
// 假设在当前卡片应用的tmp目录下有一个本地图片:head.PNG
let
tempDir
=
this
.
context
.
getApplicationContext
().
tempDir
;
// 打开本地图片并获取其打开后的fd
let
f
ile
;
try
{
file
=
fs
.
openSync
(
tempDir
+
'
/
'
+
'
head.PNG
'
);
}
catch
(
e
)
{
console
.
error
(
`openSync failed:
${
JSON
.
stringify
(
e
)}
`
);
}
let
formData
=
{
'
text
'
:
'
Image: Bear
'
,
'
imgName
'
:
'
imgBear
'
,
'
formImages
'
:
{
'
imgBear
'
:
file
.
fd
},
'
loaded
'
:
true
}
// 将fd封装在formData中并返回至卡片页面
return
formBindingData
.
createFormBindingData
(
formData
);
}
onAddForm
(
want
:
W
ant
)
{
// 假设在当前卡片应用的tmp目录下有一个本地图片:head.PNG
let
tempDir
=
this
.
context
.
getApplicationContext
().
tempDir
;
// 打开本地图片并获取其打开后的fd
let
file
:
fileFs
.
F
ile
;
let
formData
=
new
Map
<
string
,
Object
>
();
formData
.
set
(
'
text
'
,
'
Image: Bear
'
);
formData
.
set
(
'
imgName
'
,
'
imgBear
'
);
formData
.
set
(
'
loaded
'
,
true
);
try
{
file
=
fs
.
openSync
(
tempDir
+
'
/
'
+
'
head.PNG
'
);
let
imgBear
:
Record
<
string
,
number
>
=
{
'
imgBear
'
:
file
.
fd
}
formData
.
set
(
'
formImages
'
,
imgBear
);
}
catch
(
e
)
{
console
.
error
(
`openSync failed:
${
JSON
.
stringify
(
e
as
Base
.
BusinessError
)}
`
);
}
// 将fd封装在formData中并返回至卡片页面
return
formBindingData
.
createFormBindingData
(
formData
);
}
...
}
...
...
@@ -46,67 +49,67 @@
3.
在EntryFormAbility中的onFormEvent生命周期回调中实现网络文件的刷新
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
request
from
'
@ohos.request
'
;
import
fs
from
'
@ohos.file.fs
'
;
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
request
from
'
@ohos.request
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
Base
from
'
@ohos.base
'
;
import
fileFs
from
'
@ohos.file.fs
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
// 在卡片页面触发message事件时,下载一个网络图片,并将网络图片内容传递给卡片页面显示
onFormEvent
(
formId
,
message
)
{
let
formInfo
=
formBindingData
.
createFormBindingData
({
'
text
'
:
'
刷新中...
'
})
formProvider
.
updateForm
(
formId
,
formInfo
)
// 注意:FormExtensionAbility在触发生命周期回调时被拉起,仅能在后台存在5秒
// 建议下载能快速下载完成的小文件,如在5秒内未下载完成,则此次网络图片无法刷新至卡片页面上
let
netFile
=
'
https://xxxx/xxxx.png
'
;
// 需要在此处使用真实的网络图片下载链接
let
tempDir
=
this
.
context
.
getApplicationContext
().
tempDir
;
let
fileName
=
'
file
'
+
Date
.
now
();
let
tmpFile
=
tempDir
+
'
/
'
+
fileName
;
request
.
downloadFile
(
this
.
context
,
{
url
:
netFile
,
filePath
:
tmpFile
,
enableMetered
:
true
,
enableRoaming
:
true
}).
then
((
task
)
=>
{
task
.
on
(
'
complete
'
,
function
callback
()
{
console
.
info
(
'
ArkTSCard download complete:
'
+
tmpFile
);
let
file
;
try
{
file
=
fs
.
openSync
(
tmpFile
);
}
catch
(
e
)
{
console
.
error
(
`openSync failed:
${
JSON
.
stringify
(
e
)}
`
);
}
let
fileInfo
=
{};
fileInfo
[
fileName
]
=
file
.
fd
;
let
formData
=
{
'
text
'
:
'
Image:
'
+
fileName
,
'
imgName
'
:
fileName
,
'
formImages
'
:
fileInfo
,
'
loaded
'
:
true
};
let
formInfo
=
formBindingData
.
createFormBindingData
(
formData
)
formProvider
.
updateForm
(
formId
,
formInfo
).
then
((
data
)
=>
{
console
.
info
(
'
FormAbility updateForm success.
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
FormAbility updateForm failed:
'
+
JSON
.
stringify
(
error
));
})
})
task
.
on
(
'
fail
'
,
function
callBack
(
err
)
{
console
.
info
(
'
ArkTSCard download task failed. Cause:
'
+
err
);
let
formInfo
=
formBindingData
.
createFormBindingData
({
'
text
'
:
'
刷新失败
'
})
formProvider
.
updateForm
(
formId
,
formInfo
)
});
}).
catch
((
err
)
=>
{
console
.
error
(
'
Failed to request the download. Cause:
'
+
JSON
.
stringify
(
err
));
});
}
...
};
```
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
// 在卡片页面触发message事件时,下载一个网络图片,并将网络图片内容传递给卡片页面显示
onFormEvent
(
formId
:
string
,
message
:
string
)
{
let
formInfo
=
formBindingData
.
createFormBindingData
({
'
text
'
:
'
刷新中...
'
})
formProvider
.
updateForm
(
formId
,
formInfo
)
// 注意:FormExtensionAbility在触发生命周期回调时被拉起,仅能在后台存在5秒
// 建议下载能快速下载完成的小文件,如在5秒内未下载完成,则此次网络图片无法刷新至卡片页面上
let
netFile
=
'
https://xxxx/xxxx.png
'
;
// 需要在此处使用真实的网络图片下载链接
let
tempDir
=
this
.
context
.
getApplicationContext
().
tempDir
;
let
fileName
=
'
file
'
+
Date
.
now
();
let
tmpFile
=
tempDir
+
'
/
'
+
fileName
;
request
.
downloadFile
(
this
.
context
,
{
url
:
netFile
,
filePath
:
tmpFile
,
enableMetered
:
true
,
enableRoaming
:
true
}).
then
((
task
)
=>
{
task
.
on
(
'
complete
'
,
()
=>
{
console
.
info
(
'
ArkTSCard download complete:
'
+
tmpFile
);
let
file
:
fileFs
.
File
;
let
formData
=
new
Map
<
string
,
Object
>
();
try
{
file
=
fs
.
openSync
(
tmpFile
);
formData
.
set
(
'
text
'
,
'
Image: Bear
'
+
fileName
);
formData
.
set
(
'
imgName
'
,
'
imgBear
'
+
fileName
);
formData
.
set
(
'
loaded
'
,
true
);
let
imgBear
:
Record
<
string
,
number
>
=
{
'
imgBear
'
:
file
.
fd
};
formData
.
set
(
'
formImages
'
,
imgBear
);
}
catch
(
e
)
{
console
.
error
(
`openSync failed:
${
JSON
.
stringify
(
e
as
Base
.
BusinessError
)}
`
);
}
let
formInfo
=
formBindingData
.
createFormBindingData
(
formData
);
formProvider
.
updateForm
(
formId
,
formInfo
).
then
(()
=>
{
console
.
info
(
'
FormAbility updateForm success.
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
FormAbility updateForm failed:
'
+
JSON
.
stringify
(
error
));
});
})
task
.
on
(
'
fail
'
,
(
err
:
number
)
=>
{
console
.
info
(
'
ArkTSCard download task failed. Cause:
'
+
err
);
let
formInfo
=
formBindingData
.
createFormBindingData
({
'
text
'
:
'
刷新失败
'
})
formProvider
.
updateForm
(
formId
,
formInfo
)
});
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
Failed to request the download. Cause:
'
+
JSON
.
stringify
(
err
));
});
}
};
```
4.
在卡片页面通过Image组件展示EntryFormAbility传递过来的卡片内容。
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-lifecycle.md
浏览文件 @
90773e5a
...
...
@@ -20,74 +20,72 @@
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
{
Configuration
}
from
'
@ohos.app.ability.Configuration
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
import
Base
from
'
@ohos.base
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
want
)
{
console
.
info
(
'
[EntryFormAbility] onAddForm
'
);
// 在入参want中可以取出卡片的唯一标识:formId
let
formId
:
string
=
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
];
// 使用方创建卡片时触发,提供方需要返回卡片数据绑定类
let
obj
=
{
'
title
'
:
'
titleOnAddForm
'
,
'
detail
'
:
'
detailOnAddForm
'
};
let
formData
=
formBindingData
.
createFormBindingData
(
obj
);
return
formData
;
}
onCastToNormalForm
(
formId
)
{
// Called when the form provider is notified that a temporary form is successfully
// converted to a normal form.
// 使用方将临时卡片转换为常态卡片触发,提供方需要做相应的处理
console
.
info
(
`[EntryFormAbility] onCastToNormalForm, formId:
${
formId
}
`
);
}
onUpdateForm
(
formId
)
{
// 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新
console
.
info
(
'
[EntryFormAbility] onUpdateForm
'
);
let
obj
=
{
'
title
'
:
'
titleOnUpdateForm
'
,
'
detail
'
:
'
detailOnUpdateForm
'
};
let
formData
=
formBindingData
.
createFormBindingData
(
obj
);
formProvider
.
updateForm
(
formId
,
formData
).
catch
((
err
)
=>
{
if
(
err
)
{
// 异常分支打印
console
.
error
(
`[EntryFormAbility] Failed to updateForm. Code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
return
;
}
});
}
onChangeFormVisibility
(
newStatus
)
{
// Called when the form provider receives form events from the system.
// 需要配置formVisibleNotify为true,且为系统应用才会回调
console
.
info
(
'
[EntryFormAbility] onChangeFormVisibility
'
);
}
onFormEvent
(
formId
,
message
)
{
// Called when a specified message event defined by the form provider is triggered.
// 若卡片支持触发事件,则需要重写该方法并实现对事件的触发
console
.
info
(
'
[EntryFormAbility] onFormEvent
'
);
}
onRemoveForm
(
formId
)
{
// Called to notify the form provider that a specified form has been destroyed.
// 当对应的卡片删除时触发的回调,入参是被删除的卡片ID
console
.
info
(
'
[EntryFormAbility] onRemoveForm
'
);
}
onConfigurationUpdate
(
config
)
{
// 当系统配置信息置更新时触发的回调
console
.
info
(
'
[EntryFormAbility] configurationUpdate:
'
+
JSON
.
stringify
(
config
));
}
onAcquireFormState
(
want
)
{
// Called to return a {@link FormState} object.
// 卡片提供方接收查询卡片状态通知接口,默认返回卡片初始状态。
return
formInfo
.
FormState
.
READY
;
}
}
onAddForm
(
want
:
Want
)
{
console
.
info
(
'
[EntryFormAbility] onAddForm
'
);
// 使用方创建卡片时触发,提供方需要返回卡片数据绑定类
let
obj
:
Record
<
string
,
string
>
=
{
'
title
'
:
'
titleOnAddForm
'
,
'
detail
'
:
'
detailOnAddForm
'
};
let
formData
=
formBindingData
.
createFormBindingData
(
obj
);
return
formData
;
}
onCastToNormalForm
(
formId
:
string
)
{
// Called when the form provider is notified that a temporary form is successfully
// converted to a normal form.
// 使用方将临时卡片转换为常态卡片触发,提供方需要做相应的处理
console
.
info
(
`[EntryFormAbility] onCastToNormalForm, formId:
${
formId
}
`
);
}
onUpdateForm
(
formId
:
string
)
{
// 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新
console
.
info
(
'
[EntryFormAbility] onUpdateForm
'
);
let
obj
:
Record
<
string
,
string
>
=
{
'
title
'
:
'
titleOnUpdateForm
'
,
'
detail
'
:
'
detailOnUpdateForm
'
};
let
formData
=
formBindingData
.
createFormBindingData
(
obj
);
formProvider
.
updateForm
(
formId
,
formData
).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`[EntryFormAbility] Failed to updateForm. Code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
});
}
onChangeFormVisibility
(
newStatus
:
Record
<
string
,
number
>
)
{
// Called when the form provider receives form events from the system.
// 需要配置formVisibleNotify为true,且为系统应用才会回调
console
.
info
(
'
[EntryFormAbility] onChangeFormVisibility
'
);
}
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// Called when a specified message event defined by the form provider is triggered.
// 若卡片支持触发事件,则需要重写该方法并实现对事件的触发
console
.
info
(
'
[EntryFormAbility] onFormEvent
'
);
}
onRemoveForm
(
formId
:
string
)
{
// Called to notify the form provider that a specified form has been destroyed.
// 当对应的卡片删除时触发的回调,入参是被删除的卡片ID
console
.
info
(
'
[EntryFormAbility] onRemoveForm
'
);
}
onConfigurationUpdate
(
config
:
Configuration
)
{
// 当系统配置信息置更新时触发的回调
console
.
info
(
'
[EntryFormAbility] configurationUpdate:
'
+
JSON
.
stringify
(
config
));
}
onAcquireFormState
(
want
:
Want
)
{
// Called to return a {@link FormState} object.
// 卡片提供方接收查询卡片状态通知接口,默认返回卡片初始状态。
return
formInfo
.
FormState
.
READY
;
}
}
```
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-proxy.md
浏览文件 @
90773e5a
...
...
@@ -76,19 +76,22 @@
> key可以是uri也可以是简单字符串,subscriberId默认值为当前formId,实际取值都依赖于数据发布方的定义。
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
let
dataShareHelper
;
onAddForm
(
want
)
{
let
formData
=
{};
let
proxies
=
[
{
"
key
"
:
"
detail
"
,
"
subscriberId
"
:
"
11
"
}
]
let
formBinding
=
formBindingData
.
createFormBindingData
(
formData
);
formBinding
[
"
proxies
"
]
=
proxies
;
return
formBinding
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
want
:
Want
)
{
let
formData
:
Record
<
string
,
Object
>
=
{};
let
proxies
:
formBindingData
.
ProxyData
[]
=
[
{
"
key
"
:
"
detail
"
,
"
subscriberId
"
:
"
11
"
}
]
let
formBinding
=
formBindingData
.
createFormBindingData
(
formData
);
formBinding
[
"
proxies
"
]
=
proxies
;
return
formBinding
;
}
}
```
...
...
@@ -151,33 +154,38 @@
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
dataShare
from
'
@ohos.data.dataShare
'
let
dataShareHelper
;
onAddForm
(
want
)
{
let
template
=
{
predicates
:
{
"
list
"
:
"
select type from TBL00 limit 0,1
"
},
scheduler
:
""
}
let
subscriberId
=
"
111
"
;
dataShare
.
createDataShareHelper
(
this
.
context
,
"
datashareproxy://com.example.myapplication
"
,
{
isProxy
:
true
}).
then
((
data
)
=>
{
dataShareHelper
=
data
;
dataShareHelper
.
addTemplate
(
"
datashareproxy://com.example.myapplication/test
"
,
subscriberId
,
template
);
})
let
formData
=
{};
let
proxies
=
[
{
"
key
"
:
"
datashareproxy://com.example.myapplication/test
"
,
"
subscriberId
"
:
subscriberId
import
dataShare
from
'
@ohos.data.dataShare
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
let
dataShareHelper
:
dataShare
.
DataShareHelper
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
want
:
Want
)
{
let
template
:
dataShare
.
Template
=
{
predicates
:
{
"
list
"
:
"
select type from TBL00 limit 0,1
"
},
scheduler
:
""
}
]
let
formBinding
=
formBindingData
.
createFormBindingData
(
formData
);
formBinding
[
"
proxies
"
]
=
proxies
;
let
subscriberId
:
string
=
"
111
"
;
dataShare
.
createDataShareHelper
(
this
.
context
,
"
datashareproxy://com.example.myapplication
"
,
{
isProxy
:
true
}).
then
((
data
:
dataShare
.
DataShareHelper
)
=>
{
dataShareHelper
=
data
;
dataShareHelper
.
addTemplate
(
"
datashareproxy://com.example.myapplication/test
"
,
subscriberId
,
template
);
})
return
formBinding
;
let
formData
:
Record
<
string
,
Object
>
=
{};
let
proxies
:
formBindingData
.
ProxyData
[]
=
[
{
"
key
"
:
"
datashareproxy://com.example.myapplication/test
"
,
"
subscriberId
"
:
subscriberId
}
]
let
formBinding
=
formBindingData
.
createFormBindingData
(
formData
);
formBinding
[
"
proxies
"
]
=
proxies
;
return
formBinding
;
}
}
```
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-status.md
浏览文件 @
90773e5a
...
...
@@ -96,56 +96,62 @@
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
dataPreferences
from
'
@ohos.data.preferences
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
want
)
{
let
formId
=
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
];
let
isTempCard
:
boolean
=
want
.
parameters
[
formInfo
.
FormParam
.
TEMPORARY_KEY
];
if
(
isTempCard
===
false
)
{
// 如果为常态卡片,直接进行信息持久化
console
.
info
(
'
Not temp card, init db for:
'
+
formId
);
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
await
storeDB
.
put
(
'
A
'
+
formId
,
'
false
'
);
await
storeDB
.
put
(
'
B
'
+
formId
,
'
false
'
);
await
storeDB
.
flush
();
}).
catch
((
err
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
onAddForm
(
want
:
Want
)
{
let
formId
:
string
=
''
;
let
isTempCard
:
boolean
;
if
(
want
.
parameters
)
{
formId
=
JSON
.
stringify
(
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
]);
isTempCard
=
want
.
parameters
[
formInfo
.
FormParam
.
TEMPORARY_KEY
]
as
boolean
;
if
(
isTempCard
===
false
)
{
// 如果为常态卡片,直接进行信息持久化
console
.
info
(
'
Not temp card, init db for:
'
+
formId
);
let
promise
:
Promise
<
dataPreferences
.
Preferences
>
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
:
dataPreferences
.
Preferences
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
await
storeDB
.
put
(
'
A
'
+
formId
,
'
false
'
);
await
storeDB
.
put
(
'
B
'
+
formId
,
'
false
'
);
await
storeDB
.
flush
();
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
}
let
formData
=
{};
let
formData
:
Record
<
string
,
Object
|
string
>
=
{};
return
formBindingData
.
createFormBindingData
(
formData
);
}
onRemoveForm
(
formId
)
{
onRemoveForm
(
formId
:
string
)
{
console
.
info
(
'
onRemoveForm, formId:
'
+
formId
);
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
await
storeDB
.
delete
(
'
A
'
+
formId
);
await
storeDB
.
delete
(
'
B
'
+
formId
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
// 如果在添加时为临时卡片,则建议转为常态卡片时进行信息持久化
onCastToNormalForm
(
formId
)
{
onCastToNormalForm
(
formId
:
string
)
{
console
.
info
(
'
onCastToNormalForm, formId:
'
+
formId
);
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
let
promise
:
Promise
<
dataPreferences
.
Preferences
>
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
:
dataPreferences
.
Preferences
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
await
storeDB
.
put
(
'
A
'
+
formId
,
'
false
'
);
await
storeDB
.
put
(
'
B
'
+
formId
,
'
false
'
);
await
storeDB
.
flush
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
onUpdateForm
(
formId
)
{
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
onUpdateForm
(
formId
:
string
)
{
let
promise
:
Promise
<
dataPreferences
.
Preferences
>
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
:
dataPreferences
.
Preferences
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
let
stateA
=
await
storeDB
.
get
(
'
A
'
+
formId
,
'
false
'
);
let
stateB
=
await
storeDB
.
get
(
'
B
'
+
formId
,
'
false
'
);
...
...
@@ -160,18 +166,18 @@
await
formProvider
.
updateForm
(
formId
,
formInfo
);
}
console
.
info
(
`Update form success stateA:
${
stateA
}
stateB:
${
stateB
}
.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
onFormEvent
(
formId
,
message
)
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// 存放卡片状态
console
.
info
(
'
onFormEvent formId:
'
+
formId
+
'
msg:
'
+
message
);
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
let
promise
:
Promise
<
dataPreferences
.
Preferences
>
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
:
dataPreferences
.
Preferences
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
let
msg
=
JSON
.
parse
(
message
);
let
msg
:
Record
<
string
,
string
>
=
JSON
.
parse
(
message
);
if
(
msg
.
selectA
!=
undefined
)
{
console
.
info
(
'
onFormEvent selectA info:
'
+
msg
.
selectA
);
await
storeDB
.
put
(
'
A
'
+
formId
,
msg
.
selectA
);
...
...
@@ -181,7 +187,7 @@
await
storeDB
.
put
(
'
B
'
+
formId
,
msg
.
selectB
);
}
await
storeDB
.
flush
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-time.md
浏览文件 @
90773e5a
...
...
@@ -69,11 +69,12 @@
```
ts
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
Base
from
'
@ohos.base
'
;
let
formId
=
'
123456789
'
;
// 实际业务场景需要使用正确的formId
let
formId
:
string
=
'
123456789
'
;
// 实际业务场景需要使用正确的formId
try
{
// 设置过5分钟后更新卡片内容
formProvider
.
setFormNextRefreshTime
(
formId
,
5
,
(
err
,
data
)
=>
{
formProvider
.
setFormNextRefreshTime
(
formId
,
5
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to setFormNextRefreshTime. Code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
return
;
...
...
@@ -82,7 +83,7 @@
}
});
}
catch
(
err
)
{
console
.
error
(
`Failed to setFormNextRefreshTime. Code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
console
.
error
(
`Failed to setFormNextRefreshTime. Code:
${
(
err
as
Base
.
BusinessError
).
code
}
, message:
${(
err
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
zh-cn/application-dev/application-models/common-event-publish.md
浏览文件 @
90773e5a
...
...
@@ -27,19 +27,20 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
2.
传入需要发布的事件名称和回调函数,发布事件。
```
ts
// 发布公共事件
commonEventManager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
(
err
)
=>
{
commonEventManager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`[CommonEvent] PublishCallBack err=
${
JSON
.
stringify
(
err
)}
`
);
}
else
{
console
.
info
(
`[CommonEvent] Publish success`
);
}
})
})
;
```
...
...
@@ -51,13 +52,14 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
2.
传入需要发布的事件名称和回调函数,发布事件。
```
ts
// 公共事件相关信息
let
options
=
{
let
options
:
commonEventManager
.
CommonEventPublishData
=
{
code
:
1
,
// 公共事件的初始代码
data
:
"
initial data
"
,
// 公共事件的初始数据
}
...
...
@@ -67,11 +69,11 @@
```
ts
// 发布公共事件
commonEventManager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
options
,
(
err
)
=>
{
commonEventManager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
options
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
[CommonEvent] PublishCallBack err=
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
'
[CommonEvent] Publish success
'
)
}
})
})
;
```
zh-cn/application-dev/application-models/common-event-remove-sticky.md
浏览文件 @
90773e5a
...
...
@@ -22,6 +22,7 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
3.
调用
[
`removeStickyCommonEvent()`
](
../reference/apis/js-apis-commonEventManager.md#commoneventmanagerremovestickycommonevent10
)
方法移除对应的粘性公共事件。
...
...
@@ -31,7 +32,7 @@
> 移除的粘性公共事件,必须是本应用之前已发布的粘性公共事件,发布粘性公共事件参考[公共事件发布](common-event-publish.md)章节。
```
ts
commonEventManager
.
removeStickyCommonEvent
(
"
sticky_event
"
,
(
err
)
=>
{
// sticky_event粘性公共事件名
commonEventManager
.
removeStickyCommonEvent
(
"
sticky_event
"
,
(
err
:
Base
.
BusinessError
)
=>
{
// sticky_event粘性公共事件名
if
(
err
)
{
console
.
error
(
`Failed to remove sticky common event. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
...
...
zh-cn/application-dev/application-models/common-event-static-subscription.md
浏览文件 @
90773e5a
...
...
@@ -21,10 +21,11 @@
开发者可以在
[
`onReceiveEvent()`
](
../reference/apis/js-apis-application-staticSubscriberExtensionAbility.md#staticsubscriberextensionabilityonreceiveevent
)
回调中实现业务逻辑。
```
ts
import
StaticSubscriberExtensionAbility
from
'
@ohos.application.StaticSubscriberExtensionAbility
'
import
StaticSubscriberExtensionAbility
from
'
@ohos.application.StaticSubscriberExtensionAbility
'
;
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
export
default
class
StaticSubscriber
extends
StaticSubscriberExtensionAbility
{
onReceiveEvent
(
event
)
{
onReceiveEvent
(
event
:
commonEventManager
.
CommonEventData
)
{
console
.
info
(
'
onReceiveEvent, event:
'
+
event
.
event
);
}
}
...
...
zh-cn/application-dev/application-models/common-event-subscription.md
浏览文件 @
90773e5a
...
...
@@ -23,15 +23,16 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
2.
创建订阅者信息,详细的订阅者信息数据类型及包含的参数请见
[
CommonEventSubscribeInfo
](
../reference/apis/js-apis-commonEventManager.md#commoneventsubscribeinfo
)
文档介绍。
```
ts
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
let
subscriber
=
null
;
let
subscriber
:
commonEventManager
.
CommonEventSubscriber
|
null
=
null
;
// 订阅者信息
let
subscribeInfo
=
{
let
subscribeInfo
:
commonEventManager
.
CommonEventSubscribeInfo
=
{
events
:
[
"
usual.event.SCREEN_OFF
"
],
// 订阅灭屏公共事件
}
```
...
...
@@ -40,7 +41,7 @@
```
ts
// 创建订阅者回调
commonEventManager
.
createSubscriber
(
subscribeInfo
,
(
err
,
data
)
=>
{
commonEventManager
.
createSubscriber
(
subscribeInfo
,
(
err
:
Base
.
BusinessError
,
data
:
commonEventManager
.
CommonEventSubscriber
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to create subscriber. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
...
...
@@ -56,7 +57,7 @@
```
ts
// 订阅公共事件回调
if
(
subscriber
!==
null
)
{
commonEventManager
.
subscribe
(
subscriber
,
(
err
,
d
ata
)
=>
{
commonEventManager
.
subscribe
(
subscriber
,
(
err
:
Base
.
BusinessError
,
data
:
commonEventManager
.
CommonEventD
ata
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to subscribe common event. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
...
...
zh-cn/application-dev/application-models/common-event-unsubscription.md
浏览文件 @
90773e5a
...
...
@@ -19,6 +19,7 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
2.
根据
[
动态订阅公共事件
](
common-event-subscription.md
)
章节的步骤来订阅某个事件。
...
...
@@ -28,7 +29,7 @@
```
ts
// subscriber为订阅事件时创建的订阅者对象
if
(
subscriber
!==
null
)
{
commonEventManager
.
unsubscribe
(
subscriber
,
(
err
)
=>
{
commonEventManager
.
unsubscribe
(
subscriber
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`[CommonEvent] UnsubscribeCallBack err=
${
JSON
.
stringify
(
err
)}
`
);
}
else
{
...
...
zh-cn/application-dev/reference/apis/js-apis-app-form-formBindingData.md
浏览文件 @
90773e5a
...
...
@@ -63,15 +63,16 @@ createFormBindingData(obj?: Object | string): FormBindingData
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
Base
from
'
@ohos.base
'
;
try
{
let
fd
=
fs
.
openSync
(
'
/path/to/form.png
'
);
let
createFormBindingDataParam
=
new
Map
<
Object
,
string
|
object
>
()
let
formImagesParam
=
new
Map
<
Object
,
object
>
()
formImagesParam
.
set
(
'
image
'
,
fd
)
createFormBindingDataParam
.
set
(
"
name
"
,
'
21°
'
)
createFormBindingDataParam
.
set
(
'
formImages
'
,
formImagesParam
)
let
createFormBindingDataParam
=
new
Map
<
string
,
string
|
Object
>
();
let
formImagesParam
=
new
Map
<
string
,
Object
>
();
formImagesParam
.
set
(
'
image
'
,
fd
)
;
createFormBindingDataParam
.
set
(
"
name
"
,
'
21°
'
)
;
createFormBindingDataParam
.
set
(
'
formImages
'
,
formImagesParam
)
;
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
}
catch
(
error
)
{
...
...
zh-cn/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md
浏览文件 @
90773e5a
...
...
@@ -51,7 +51,7 @@ import Want from '@ohos.app.ability.Want';
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onAddForm
(
want
:
Want
)
{
console
.
log
(
`FormExtensionAbility onAddForm, want:
${
want
.
abilityName
}
`
);
let
dataObj1
=
new
Map
<
Object
,
string
>
();
let
dataObj1
=
new
Map
<
string
,
string
>
();
dataObj1
.
set
(
'
temperature
'
,
'
11c
'
);
dataObj1
.
set
(
'
time
'
,
'
11:00
'
);
...
...
@@ -107,20 +107,19 @@ onUpdateForm(formId: string): void
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
Base
from
'
@ohos.base
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onUpdateForm
(
formId
:
string
)
{
console
.
log
(
`FormExtensionAbility onUpdateForm, formId:
${
formId
}
`
);
class
createFormBindingDataParam
{
temperature
:
string
time
:
string
}
let
obj2
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
}
as
createFormBindingDataParam
);
});
formProvider
.
updateForm
(
formId
,
obj2
).
then
((
data
)
=>
{
console
.
log
(
`FormExtensionAbility context updateForm, data:
${
data
}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`FormExtensionAbility context updateForm failed, data:
${
error
}
`
);
});
}
};
...
...
@@ -146,6 +145,7 @@ onChangeFormVisibility(newStatus: { [key: string]: number }): void
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
Base
from
'
@ohos.base
'
;
// 由于arkTs中无Object.keys,且无法使用for..in...
// 若报arkTs问题,请将此方法单独抽离至一个ts文件中并暴露,在需要用到的ets文件中引入使用
...
...
@@ -155,23 +155,21 @@ function getObjKeys(obj: Object): string[] {
}
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onChangeFormVisibility
(
newStatus
)
{
onChangeFormVisibility
(
newStatus
:
Record
<
string
,
number
>
)
{
console
.
log
(
`FormExtensionAbility onChangeFormVisibility, newStatus:
${
newStatus
}
`
);
class
createFormBindingDataParam
{
temperature
:
string
time
:
string
}
let
obj2
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
}
as
createFormBindingDataParam
);
for
(
let
key
in
newStatus
)
{
console
.
log
(
`FormExtensionAbility onChangeFormVisibility, key:
${
key
}
, value=
${
newStatus
[
key
]}
`
);
formProvider
.
updateForm
(
key
,
obj2
).
then
((
data
)
=>
{
console
.
log
(
`FormExtensionAbility context updateForm, data:
${
data
}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`Operation updateForm failed. Cause:
${
error
}
`
);
});
let
keys
:
string
[]
=
getObjKeys
(
newStatus
);
for
(
let
i
:
number
=
0
;
i
<
keys
.
length
;
i
++
)
{
console
.
log
(
`FormExtensionAbility onChangeFormVisibility, key:
${
keys
[
i
]}
, value=
${
newStatus
[
keys
[
i
]]}
`
);
formProvider
.
updateForm
(
keys
[
i
],
obj2
).
then
(()
=>
{
console
.
log
(
`FormExtensionAbility context updateForm`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`Operation updateForm failed. Cause:
${
JSON
.
stringify
(
error
)}
`
);
});
}
}
...
...
@@ -317,9 +315,9 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onShareForm
(
formId
:
string
)
{
console
.
log
(
`FormExtensionAbility onShareForm, formId:
${
formId
}
`
);
let
wantParams
=
{
let
wantParams
:
Record
<
string
,
Object
>
=
{
'
temperature
'
:
'
20
'
,
'
time
'
:
'
2022-8-8 09:59
'
,
s
'
time
'
:
'
2022-8-8 09:59
'
,
};
return
wantParams
;
}
...
...
@@ -355,8 +353,8 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onAcquireFormData
(
formId
:
string
)
{
console
.
log
(
'
FormExtensionAbility onAcquireFormData, formId: ${formId}
'
);
let
wantParams
=
{
console
.
log
(
`FormExtensionAbility onAcquireFormData, formId:
${
formId
}
`
);
let
wantParams
:
Record
<
string
,
Object
>
=
{
'
temperature
'
:
'
20
'
,
'
time
'
:
'
2022-8-8 09:59
'
,
};
...
...
zh-cn/application-dev/reference/apis/js-apis-app-form-formHost.md
浏览文件 @
90773e5a
...
...
@@ -61,7 +61,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -114,10 +114,10 @@ try {
formHost
.
deleteForm
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost deleteForm success
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost deleteForm, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost deleteForm, error:
${
JSON
.
stringify
(
error
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -167,7 +167,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -218,7 +218,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -274,7 +274,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -324,7 +324,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -379,7 +379,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -430,7 +430,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -485,7 +485,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -533,7 +533,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -586,7 +586,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -634,7 +634,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -687,7 +687,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -736,7 +736,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -790,7 +790,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -840,7 +840,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -895,7 +895,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -935,7 +935,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -974,7 +974,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1023,7 +1023,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1069,7 +1069,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1120,7 +1120,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1172,7 +1172,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1227,7 +1227,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1277,7 +1277,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1330,7 +1330,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1392,7 +1392,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1457,7 +1457,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1575,7 +1575,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1630,7 +1630,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1680,7 +1680,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1735,7 +1735,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
## shareForm
...
...
@@ -1785,7 +1785,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1841,7 +1841,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1890,7 +1890,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1942,7 +1942,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1990,7 +1990,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -2041,6 +2041,6 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
zh-cn/application-dev/reference/apis/js-apis-app-form-formProvider.md
浏览文件 @
90773e5a
...
...
@@ -57,7 +57,7 @@ try {
console
.
log
(
`formProvider setFormNextRefreshTime success`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -110,7 +110,7 @@ try {
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -152,15 +152,10 @@ import Base from '@ohos.base';
let
formId
:
string
=
'
12400633174999288
'
;
try
{
class
createFormBindingDataParamType
{
temperature
:
string
time
:
string
}
let
createFormBindingDataParam
:
createFormBindingDataParamType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
let
obj
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
updateForm
(
formId
,
obj
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
...
...
@@ -169,7 +164,7 @@ try {
console
.
log
(
`formProvider updateForm success`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -215,23 +210,18 @@ import formBindingData from '@ohos.app.form.formBindingData';
import
Base
from
'
@ohos.base
'
;
let
formId
:
string
=
'
12400633174999288
'
;
class
createFormBindingDataParamType
{
temperature
:
string
time
:
string
}
let
createFormBindingDataParam
:
createFormBindingDataParamType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
let
obj
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
try
{
formProvider
.
updateForm
(
formId
,
obj
).
then
(()
=>
{
console
.
log
(
`formProvider updateForm success`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`promise error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -272,7 +262,7 @@ try {
console
.
log
(
`formProvider getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
## getFormsInfo
...
...
@@ -319,7 +309,7 @@ try {
console
.
log
(
`formProvider getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -371,7 +361,7 @@ try {
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -421,24 +411,19 @@ let want: Want = {
}
};
try
{
class
createFormBindingDataParamType
{
temperature
:
string
time
:
string
}
let
createFormBindingDataParam
:
createFormBindingDataParamType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
let
obj
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
requestPublishForm
(
want
,
obj
,
(
error
:
Base
.
BusinessError
,
data
:
string
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`callback error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
return
;
}
console
.
log
(
'
formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}
'
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -494,7 +479,7 @@ try {
console
.
log
(
`formProvider requestPublishForm, form ID is:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -554,7 +539,7 @@ try {
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -614,13 +599,13 @@ try {
console
.
log
(
`formProvider requestPublishForm, form ID is:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
}
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -674,13 +659,13 @@ try {
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
}
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-application-formBindingData.md
浏览文件 @
90773e5a
...
...
@@ -50,6 +50,7 @@ createFormBindingData(obj?: Object | string): FormBindingData
```
ts
import
formBindingData
from
'
@ohos.application.formBindingData
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
Base
from
'
@ohos.base
'
;
try
{
let
fd
=
fs
.
openSync
(
'
/path/to/form.png
'
);
...
...
@@ -61,6 +62,6 @@ try {
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
}
catch
(
error
)
{
console
.
error
(
'
catch error, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`catch error, error:
${
JSON
.
stringify
(
error
as
Base
.
BusinessError
)}
`
);
}
```
zh-cn/application-dev/reference/apis/js-apis-application-formHost.md
浏览文件 @
90773e5a
...
...
@@ -37,9 +37,9 @@ deleteForm(formId: string, callback: AsyncCallback<void>): void
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
deleteForm
(
formId
,
(
error
,
data
)
=>
{
formHost
.
deleteForm
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost deleteForm, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost deleteForm, error:
${
JSON
.
stringify
(
error
)}
`
);
}
});
```
...
...
@@ -344,7 +344,7 @@ import Base from '@ohos.base';
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyVisibleForms
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost notifyVisibleForms, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost notifyVisibleForms, error:
${
JSON
.
stringify
(
error
)}
`
);
}
});
```
...
...
zh-cn/application-dev/reference/apis/js-apis-application-formProvider.md
浏览文件 @
90773e5a
...
...
@@ -97,16 +97,11 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
Base
from
'
@ohos.base
'
let
formId
=
'
12400633174999288
'
;
class
createBindingDataType
{
temperature
:
string
time
:
string
};
let
createBindingDataParam
:
createBindingDataType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createBindingDataParam
);
let
formId
:
string
=
'
12400633174999288
'
;
let
obj
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
updateForm
(
formId
,
obj
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
`formProvider updateForm, error:
${
JSON
.
stringify
(
error
)}
`
);
...
...
@@ -142,15 +137,10 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
import
Base
from
'
@ohos.base
'
let
formId
:
string
=
'
12400633174999288
'
;
class
createBindingDataType
{
temperature
:
string
time
:
string
};
let
createBindingDataParam
:
createBindingDataType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createBindingDataParam
);
let
obj
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
updateForm
(
formId
,
obj
).
then
(()
=>
{
console
.
log
(
'
formProvider updateForm success
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
...
...
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
浏览文件 @
90773e5a
...
...
@@ -11,8 +11,6 @@
```
ts
import
CommonEvent
from
'
@ohos.commonEvent
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
## Support
...
...
@@ -42,6 +40,8 @@ publish(event: string, callback: AsyncCallback\<void>): void
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//发布公共事件回调
function
publishCB
(
err
:
Base
.
BusinessError
)
{
if
(
err
.
code
)
{
...
...
@@ -78,6 +78,9 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
//公共事件相关信息
let
options
:
CommonEventManager
.
CommonEventPublishData
=
{
code
:
0
,
//公共事件的初始代码
...
...
@@ -122,6 +125,8 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
// 发布公共事件回调
function
publishCB
(
err
:
Base
.
BusinessError
)
{
if
(
err
.
code
)
{
...
...
@@ -164,6 +169,9 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
// 公共事件相关信息
let
options
:
CommonEventManager
.
CommonEventPublishData
=
{
code
:
0
,
// 公共事件的初始代码
...
...
@@ -208,6 +216,9 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
...
...
@@ -254,6 +265,9 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
...
...
@@ -291,6 +305,9 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
...
...
@@ -344,6 +361,9 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
...
...
zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md
浏览文件 @
90773e5a
...
...
@@ -10,7 +10,6 @@
```
ts
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
## Support
...
...
@@ -48,6 +47,8 @@ publish(event: string, callback: AsyncCallback\<void>): void
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//发布公共事件回调
function
publishCB
(
err
:
Base
.
BusinessError
)
{
if
(
err
)
{
...
...
@@ -96,6 +97,8 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//公共事件相关信息
let
options
:
CommonEventManager
.
CommonEventPublishData
=
{
code
:
0
,
//公共事件的初始代码
...
...
@@ -153,6 +156,8 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//发布公共事件回调
function
publishCB
(
err
:
Base
.
BusinessError
)
{
if
(
err
)
{
...
...
@@ -208,6 +213,8 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
```
ts
import
Base
from
'
@ohos.base
'
;
//公共事件相关信息
let
options
:
CommonEventManager
.
CommonEventPublishData
=
{
code
:
0
,
//公共事件的初始代码
...
...
@@ -253,6 +260,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
...
...
@@ -301,6 +310,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
...
...
@@ -340,6 +351,8 @@ createSubscriber的同步接口。
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
...
...
@@ -385,6 +398,8 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//订阅者信息
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
...
...
@@ -456,6 +471,8 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
let
subscribeInfo
:
CommonEventManager
.
CommonEventSubscribeInfo
=
{
...
...
@@ -543,6 +560,8 @@ removeStickyCommonEvent(event: string, callback: AsyncCallback\<void>): void
```
ts
import
Base
from
'
@ohos.base
'
;
CommonEventManager
.
removeStickyCommonEvent
(
"
sticky_event
"
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
info
(
`Remove sticky event AsyncCallback failed, errCode:
${
err
.
code
}
, errMes:
${
err
.
message
}
`
);
...
...
@@ -590,6 +609,8 @@ removeStickyCommonEvent(event: string): Promise\<void>
```
ts
import
Base
from
'
@ohos.base
'
;
CommonEventManager
.
removeStickyCommonEvent
(
"
sticky_event
"
).
then
(()
=>
{
console
.
info
(
`Remove sticky event AsyncCallback success`
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
...
...
@@ -627,6 +648,8 @@ setStaticSubscriberState(enable: boolean, callback: AsyncCallback\<void>): void;
```
ts
import
Base
from
'
@ohos.base
'
;
CommonEventManager
.
setStaticSubscriberState
(
true
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
!
err
)
{
console
.
info
(
`Set static subscriber state callback failed, err is null.`
);
...
...
@@ -675,6 +698,8 @@ setStaticSubscriberState(enable: boolean): Promise\<void>;
```
ts
import
Base
from
'
@ohos.base
'
;
CommonEventManager
.
setStaticSubscriberState
(
false
).
then
(()
=>
{
console
.
info
(
`Set static subscriber state promise success`
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
...
...
zh-cn/application-dev/reference/apis/js-apis-emitter.md
浏览文件 @
90773e5a
...
...
@@ -10,8 +10,8 @@
## 导入模块
```
javascript
import
emitter
from
'
@ohos.events.emitter
'
```
ts
import
emitter
from
'
@ohos.events.emitter
'
;
```
## 权限列表
...
...
@@ -35,16 +35,15 @@ on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)
**示例:**
```
javascript
let
innerEvent
=
{
eventId
:
1
```
ts
let
innerEvent
:
emitter
.
InnerEvent
=
{
eventId
:
1
};
// 收到eventId为1的事件后执行该回调函数
function
emitterCallback
()
{
console
.
info
(
'
callback
'
);
}
emitter
.
on
(
innerEvent
,
emitterCallback
);
// 收到eventId为1的事件后执行回调函数
emitter
.
on
(
innerEvent
,
()
=>
{
console
.
info
(
'
callback
'
);
});
```
## emitter.once
...
...
@@ -64,16 +63,15 @@ once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdat
**示例:**
```
javascript
let
innerEvent
=
{
```
ts
let
innerEvent
:
emitter
.
InnerEvent
=
{
eventId
:
1
};
// 收到eventId为1的事件后执行该回调函数
function
emitterCallback
()
{
emitter
.
once
(
innerEvent
,
()
=>
{
console
.
info
(
'
once callback
'
);
};
emitter
.
once
(
innerEvent
,
emitterCallback
);
});
```
## emitter.off
...
...
@@ -92,7 +90,7 @@ off(eventId: number): void
**示例:**
```
javascript
```
ts
// 取消eventID为1的所有事件回调处理函数
emitter
.
off
(
1
);
```
...
...
@@ -114,13 +112,12 @@ off(eventId: number, callback: Callback\<[EventData](#eventdata)\>): void
**示例:**
```
javascript
```
ts
// 取消eventID为1的事件回调处理函数 emitterCallback
// 如果该回调处理函数没有被订阅,则不做任何处理
function
emitterCallback
()
{
console
.
info
(
'
callback
'
);
}
emitter
.
off
(
1
,
emitterCallback
);
emitter
.
off
(
1
,
()
=>
{
console
.
info
(
'
callback
'
);
});
```
## emitter.emit
...
...
@@ -140,15 +137,15 @@ emit(event: [InnerEvent](#innerevent), data?: [EventData](#eventdata)): void
**示例:**
```
javascript
let
eventData
=
{
```
ts
let
eventData
:
emitter
.
EventData
=
{
data
:
{
"
content
"
:
"
c
"
,
"
id
"
:
1
,
}
};
let
innerEvent
=
{
let
innerEvent
:
emitter
.
InnerEvent
=
{
eventId
:
1
,
priority
:
emitter
.
EventPriority
.
HIGH
};
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md
浏览文件 @
90773e5a
...
...
@@ -66,7 +66,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
};
this
.
context
.
startAbility
(
want
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
'
FormExtensionContext startAbility, error:${JSON.stringify(error)}
'
);
console
.
error
(
`FormExtensionContext startAbility, error:
${
JSON
.
stringify
(
error
)}
`
);
}
else
{
console
.
log
(
'
FormExtensionContext startAbility success
'
);
}
...
...
@@ -213,7 +213,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
connection
=
this
.
context
.
connectServiceExtensionAbility
(
want
,
options
);
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
console
.
error
(
`error.code:
${
(
paramError
as
Base
.
BusinessError
).
code
}
, error.message:
${(
paramError
as
Base
.
BusinessError
)
.
message
}
`
);
}
}
};
...
...
@@ -275,7 +275,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
}
catch
(
paramError
)
{
commRemote
=
null
;
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
console
.
error
(
`error.code:
${
(
paramError
as
Base
.
BusinessError
).
code
}
, error.message:
${(
paramError
as
Base
.
BusinessError
)
.
message
}
`
);
}
}
};
...
...
@@ -343,7 +343,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
}
catch
(
paramError
)
{
commRemote
=
null
;
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
console
.
error
(
`error.code:
${
(
paramError
as
Base
.
BusinessError
).
code
}
, error.message:
${(
paramError
as
Base
.
BusinessError
)
.
message
}
`
);
}
}
};
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationFlags.md
浏览文件 @
90773e5a
...
...
@@ -8,6 +8,8 @@
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Notification.Notification
## 属性
| 名称 | 类型 | 必填 | 说明 |
| ---------------- | ---------------------- | ---- | --------------------------------- |
| soundEnabled |
[
NotificationFlagStatus
](
#notificationflagstatus
)
| 否 | 是否启用声音提示。 |
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationSubscriber.md
浏览文件 @
90773e5a
...
...
@@ -32,23 +32,25 @@ onConsume?: (data: [SubscribeCallbackData](js-apis-notification.md#subscribecall
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onConsumeCallback
(
data
)
{
console
.
info
(
'
===> onConsume in test
'
);
let
req
=
data
.
request
;
console
.
info
(
'
===> onConsume callback req.id:
'
+
req
.
id
);
let
onConsumeCallback
=
(
data
:
notificationSubscribe
.
SubscribeCallbackData
)
=>
{
console
.
info
(
'
===> onConsume in test
'
);
let
req
=
data
.
request
;
console
.
info
(
'
===> onConsume callback req.id:
'
+
req
.
id
);
};
let
subscriber
=
{
onConsume
:
onConsumeCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onConsume
:
onConsumeCallback
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
@@ -72,23 +74,25 @@ onCancel?:(data: [SubscribeCallbackData](js-apis-notification.md#subscribecallba
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onCancelCallback
(
data
)
{
console
.
info
(
'
===> onCancel in test
'
);
let
req
=
data
.
request
;
console
.
info
(
'
===> onCancel callback req.id:
'
+
req
.
id
);
function
onCancelCallback
(
data
:
notificationSubscribe
.
SubscribeCallbackData
)
{
console
.
info
(
'
===> onCancel in test
'
);
let
req
=
data
.
request
;
console
.
info
(
'
===> onCancel callback req.id:
'
+
req
.
id
);
}
let
subscriber
=
{
onCancel
:
onCancelCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onCancel
:
onCancelCallback
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
@@ -112,21 +116,21 @@ onUpdate?:(data: [NotificationSortingMap](js-apis-notification.md#notificationso
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onUpdateCallback
(
map
)
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onUpdate
:
(
map
)
=>
{
console
.
info
(
'
===> onUpdateCallback map:
'
+
JSON
.
stringify
(
map
));
}
let
subscriber
=
{
onUpdate
:
onUpdateCallback
}
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
@@ -144,21 +148,23 @@ onConnect?:() => void
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onConnectCallback
()
{
console
.
info
(
'
===> onConnect in test
'
);
let
onConnectCallback
=
()
=>
{
console
.
info
(
'
===> onConnect in test
'
);
}
let
subscriber
=
{
onConnect
:
onConnectCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onConnect
:
onConnectCallback
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
@@ -176,32 +182,34 @@ onDisconnect?:() => void
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
unsubscribeCallback
(
err
)
{
if
(
err
.
code
)
{
console
.
error
(
`unsubscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
unsubscribeCallback
"
);
}
let
unsubscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`unsubscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
unsubscribeCallback
"
);
}
};
function
onConnectCallback
()
{
console
.
info
(
'
===> onConnect in test
'
);
let
onConnectCallback
=
()
=>
{
console
.
info
(
'
===> onConnect in test
'
);
}
function
onDisconnectCallback
()
{
console
.
info
(
'
===> onDisconnect in test
'
);
let
onDisconnectCallback
=
()
=>
{
console
.
info
(
'
===> onDisconnect in test
'
);
}
let
subscriber
=
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
};
// 订阅通知后会收到onConnect回调
...
...
@@ -222,21 +230,23 @@ onDestroy?:() => void
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onDestroyCallback
()
{
console
.
info
(
'
===> onDestroy in test
'
);
let
onDestroyCallback
=
()
=>
{
console
.
info
(
'
===> onDestroy in test
'
);
}
let
subscriber
=
{
onDestroy
:
onDestroyCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onDestroy
:
onDestroyCallback
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
@@ -260,21 +270,23 @@ onDoNotDisturbDateChange?:(mode: notification.[DoNotDisturbDate](js-apis-notific
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onDoNotDisturbDateChangeCallback
(
mode
)
{
console
.
info
(
'
===> onDoNotDisturbDateChange:
'
+
mode
);
let
onDoNotDisturbDateChangeCallback
=
(
mode
:
NotificationManager
.
DoNotDisturbDate
)
=>
{
console
.
info
(
'
===> onDoNotDisturbDateChange:
'
+
mode
);
}
let
subscriber
=
{
onDoNotDisturbDateChange
:
onDoNotDisturbDateChangeCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onDoNotDisturbDateChange
:
onDoNotDisturbDateChangeCallback
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
@@ -299,23 +311,25 @@ onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](j
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onEnabledNotificationChangedCallback
(
callbackData
)
{
console
.
info
(
"
bundle:
"
,
callbackData
.
bundle
);
console
.
info
(
"
uid:
"
,
callbackData
.
uid
);
console
.
info
(
"
enable:
"
,
callbackData
.
enable
);
let
onEnabledNotificationChangedCallback
=
(
callbackData
:
notificationSubscribe
.
EnabledNotificationCallbackData
)
=>
{
console
.
info
(
"
bundle:
"
,
callbackData
.
bundle
);
console
.
info
(
"
uid:
"
,
callbackData
.
uid
);
console
.
info
(
"
enable:
"
,
callbackData
.
enable
);
};
let
subscriber
=
{
onEnabledNotificationChanged
:
onEnabledNotificationChangedCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onEnabledNotificationChanged
:
onEnabledNotificationChangedCallback
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
@@ -339,23 +353,23 @@ notificationSubscribe.subscribe(subscriber, subscribeCallback);
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
onBadgeChangedCallback
(
data
)
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onBadgeChanged
:
(
data
)
=>
{
console
.
info
(
"
bundle:
"
,
data
.
bundle
);
console
.
info
(
"
uid:
"
,
data
.
uid
);
console
.
info
(
"
badgeNumber:
"
,
data
.
badgeNumber
);
};
let
subscriber
=
{
onBadgeChanged
:
onBadgeChangedCallback
}
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
zh-cn/application-dev/reference/apis/js-apis-notification.md
浏览文件 @
90773e5a
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-notificationManager.md
浏览文件 @
90773e5a
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md
浏览文件 @
90773e5a
...
...
@@ -8,7 +8,7 @@
## 导入模块
```
j
s
```
t
s
import
notificationSubscribe
from
'
@ohos.notificationSubscribe
'
;
```
...
...
@@ -45,23 +45,25 @@ subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, c
**示例:**
```
js
```
ts
import
Base
from
'
@ohos.base
'
;
//subscribe回调
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribe success
"
);
}
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribe success
"
);
}
}
function
onConsumeCallback
(
data
)
{
console
.
info
(
"
Consume callback:
"
+
JSON
.
stringify
(
data
));
let
onConsumeCallback
=
(
data
:
notificationSubscribe
.
SubscribeCallbackData
)
=>
{
console
.
info
(
"
Consume callback:
"
+
JSON
.
stringify
(
data
));
}
let
subscriber
=
{
onConsume
:
onConsumeCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onConsume
:
onConsumeCallback
};
let
info
=
{
bundleNames
:
[
"
bundleName1
"
,
"
bundleName2
"
]
let
info
:
notificationSubscribe
.
NotificationSubscribeInfo
=
{
bundleNames
:
[
"
bundleName1
"
,
"
bundleName2
"
]
};
notificationSubscribe
.
subscribe
(
subscriber
,
info
,
subscribeCallback
);
```
...
...
@@ -98,19 +100,21 @@ subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>):
**示例:**
```
js
function
subscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribe success
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribe success
"
);
}
}
function
onConsumeCallback
(
data
)
{
console
.
info
(
"
Consume callback:
"
+
JSON
.
stringify
(
data
));
let
onConsumeCallback
=
(
data
:
notificationSubscribe
.
SubscribeCallbackData
)
=>
{
console
.
info
(
"
Consume callback:
"
+
JSON
.
stringify
(
data
));
}
let
subscriber
=
{
onConsume
:
onConsumeCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onConsume
:
onConsumeCallback
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
```
...
...
@@ -149,15 +153,19 @@ subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo):
**示例:**
```
js
function
onConsumeCallback
(
data
)
{
console
.
info
(
"
Consume callback:
"
+
JSON
.
stringify
(
data
));
```
ts
import
Base
from
'
@ohos.base
'
;
let
onConsumeCallback
=
(
data
:
notificationSubscribe
.
SubscribeCallbackData
)
=>
{
console
.
info
(
"
Consume callback:
"
+
JSON
.
stringify
(
data
));
}
let
subscriber
=
{
onConsume
:
onConsumeCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onConsume
:
onConsumeCallback
};
notificationSubscribe
.
subscribe
(
subscriber
).
then
(()
=>
{
console
.
info
(
"
subscribe success
"
);
console
.
info
(
"
subscribe success
"
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
error
(
"
subscribe fail:
"
+
JSON
.
stringify
(
err
));
});
```
...
...
@@ -194,19 +202,21 @@ unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>)
**示例:**
```
js
function
unsubscribeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`unsubscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
unsubscribe success
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
unsubscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`unsubscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
unsubscribe success
"
);
}
}
function
onDisconnectCallback
()
{
console
.
info
(
"
subscribe disconnect
"
);
let
onDisconnectCallback
=
()
=>
{
console
.
info
(
"
subscribe disconnect
"
);
}
let
subscriber
=
{
onDisconnect
:
onDisconnectCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onDisconnect
:
onDisconnectCallback
};
notificationSubscribe
.
unsubscribe
(
subscriber
,
unsubscribeCallback
);
```
...
...
@@ -241,15 +251,19 @@ unsubscribe(subscriber: NotificationSubscriber): Promise\<void\>
**示例:**
```
js
function
onDisconnectCallback
()
{
console
.
info
(
"
subscribe disconnect
"
);
```
ts
import
Base
from
'
@ohos.base
'
;
let
onDisconnectCallback
=
()
=>
{
console
.
info
(
"
subscribe disconnect
"
);
}
let
subscriber
=
{
onDisconnect
:
onDisconnectCallback
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onDisconnect
:
onDisconnectCallback
};
notificationSubscribe
.
unsubscribe
(
subscriber
).
then
(()
=>
{
console
.
info
(
"
unsubscribe success
"
);
console
.
info
(
"
unsubscribe success
"
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
error
(
"
unsubscribe fail:
"
+
JSON
.
stringify
(
err
));
});
```
...
...
@@ -288,22 +302,25 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
**示例:**
```
js
function
removeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`remove failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
remove success
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
import
NotificationManager
from
'
@ohos.notificationManager
'
;
let
removeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`remove failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
remove success
"
);
}
}
let
bundle
=
{
bundle
:
"
bundleName1
"
,
let
bundle
:
NotificationManager
.
BundleOption
=
{
bundle
:
"
bundleName1
"
,
};
let
notificationKey
=
{
id
:
0
,
label
:
"
label
"
,
let
notificationKey
:
notificationSubscribe
.
NotificationKey
=
{
id
:
0
,
label
:
"
label
"
,
};
let
reason
=
notificationSubscribe
.
RemoveReason
.
CLICK_REASON_REMOVE
;
let
reason
:
notificationSubscribe
.
RemoveReason
=
notificationSubscribe
.
RemoveReason
.
CLICK_REASON_REMOVE
;
notificationSubscribe
.
remove
(
bundle
,
notificationKey
,
reason
,
removeCallback
);
```
...
...
@@ -343,17 +360,22 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
**示例:**
```
js
let
bundle
=
{
bundle
:
"
bundleName1
"
,
```
ts
import
Base
from
'
@ohos.base
'
;
import
NotificationManager
from
'
@ohos.notificationManager
'
;
let
bundle
:
NotificationManager
.
BundleOption
=
{
bundle
:
"
bundleName1
"
,
};
let
notificationKey
=
{
id
:
0
,
label
:
"
label
"
,
let
notificationKey
:
notificationSubscribe
.
NotificationKey
=
{
id
:
0
,
label
:
"
label
"
,
};
let
reason
=
notificationSubscribe
.
RemoveReason
.
CLICK_REASON_REMOVE
;
let
reason
:
notificationSubscribe
.
RemoveReason
=
notificationSubscribe
.
RemoveReason
.
CLICK_REASON_REMOVE
;
notificationSubscribe
.
remove
(
bundle
,
notificationKey
,
reason
).
then
(()
=>
{
console
.
info
(
"
remove success
"
);
console
.
info
(
"
remove success
"
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
error
(
"
remove fail:
"
+
JSON
.
stringify
(
err
));
});
```
...
...
@@ -390,17 +412,19 @@ remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>):
**示例:**
```
j
s
let
hashCode
=
'
hashCod
e
'
;
```
t
s
import
Base
from
'
@ohos.bas
e
'
;
function
removeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`remove failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
remove success
"
);
}
let
hashCode
:
string
=
'
hashCode
'
;
let
removeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`remove failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
remove success
"
);
}
}
let
reason
=
notificationSubscribe
.
RemoveReason
.
CANCEL_REASON_REMOVE
;
let
reason
:
notificationSubscribe
.
RemoveReason
=
notificationSubscribe
.
RemoveReason
.
CANCEL_REASON_REMOVE
;
notificationSubscribe
.
remove
(
hashCode
,
reason
,
removeCallback
);
```
...
...
@@ -436,11 +460,15 @@ remove(hashCode: string, reason: RemoveReason): Promise\<void\>
**示例:**
```
js
let
hashCode
=
'
hashCode
'
;
let
reason
=
notificationSubscribe
.
RemoveReason
.
CLICK_REASON_REMOVE
;
```
ts
import
Base
from
'
@ohos.base
'
;
let
hashCode
:
string
=
'
hashCode
'
;
let
reason
:
notificationSubscribe
.
RemoveReason
=
notificationSubscribe
.
RemoveReason
.
CLICK_REASON_REMOVE
;
notificationSubscribe
.
remove
(
hashCode
,
reason
).
then
(()
=>
{
console
.
info
(
"
remove success
"
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
error
(
"
remove fail:
"
+
JSON
.
stringify
(
err
));
});
```
## NotificationSubscribe.remove<sup>10+<sup>
...
...
@@ -475,17 +503,19 @@ remove(hashCodes: Array\<String\>, reason: RemoveReason, callback: AsyncCallback
**示例:**
```
j
s
let
hashCodes
=
[
'
hashCode1
'
,
'
hashCode2
'
]
;
```
t
s
import
Base
from
'
@ohos.base
'
;
function
removeCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`remove failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
remove success
"
);
}
let
hashCodes
:
string
[]
=
[
'
hashCode1
'
,
'
hashCode2
'
];
let
removeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`remove failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
remove success
"
);
}
}
let
reason
=
notificationSubscribe
.
RemoveReason
.
CANCEL_REASON_REMOVE
;
let
reason
:
notificationSubscribe
.
RemoveReason
=
notificationSubscribe
.
RemoveReason
.
CANCEL_REASON_REMOVE
;
notificationSubscribe
.
remove
(
hashCodes
,
reason
,
removeCallback
);
```
...
...
@@ -520,11 +550,15 @@ remove(hashCodes: Array\<String\>, reason: RemoveReason): Promise\<void\>
**示例:**
```
js
let
hashCodes
=
[
'
hashCode1
'
,
'
hashCode2
'
];
let
reason
=
notificationSubscribe
.
RemoveReason
.
CLICK_REASON_REMOVE
;
```
ts
import
Base
from
'
@ohos.base
'
;
let
hashCodes
:
string
[]
=
[
'
hashCode1
'
,
'
hashCode2
'
];
let
reason
:
notificationSubscribe
.
RemoveReason
=
notificationSubscribe
.
RemoveReason
.
CLICK_REASON_REMOVE
;
notificationSubscribe
.
remove
(
hashCodes
,
reason
).
then
(()
=>
{
console
.
info
(
"
remove success
"
);
console
.
info
(
"
remove success
"
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
error
(
"
remove fail:
"
+
JSON
.
stringify
(
err
));
});
```
...
...
@@ -560,16 +594,18 @@ removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void
**示例:**
```
js
function
removeAllCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`removeAll failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
removeAll success
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
removeAllCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`removeAll failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
removeAll success
"
);
}
}
let
bundle
=
{
bundle
:
"
bundleName1
"
,
let
bundle
:
notificationSubscribe
.
BundleOption
=
{
bundle
:
"
bundleName1
"
,
};
notificationSubscribe
.
removeAll
(
bundle
,
removeAllCallback
);
```
...
...
@@ -604,8 +640,10 @@ removeAll(callback: AsyncCallback\<void\>): void
**示例:**
```
js
function
removeAllCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
removeAllCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`removeAll failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
...
...
@@ -647,10 +685,14 @@ removeAll(bundle?: BundleOption): Promise\<void\>
**示例:**
```
js
```
ts
import
Base
from
'
@ohos.base
'
;
// 不指定应用时,删除所有通知
notificationSubscribe
.
removeAll
().
then
(()
=>
{
console
.
info
(
"
removeAll success
"
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
error
(
"
removeAll fail:
"
+
JSON
.
stringify
(
err
));
});
```
...
...
@@ -686,16 +728,18 @@ removeAll(userId: number, callback: AsyncCallback\<void>): void
**示例:**
```
js
function
removeAllCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`removeAll failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
removeAll success
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
removeAllCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`removeAll failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
removeAll success
"
);
}
}
let
userId
=
1
;
let
userId
:
number
=
1
;
notificationSubscribe
.
removeAll
(
userId
,
removeAllCallback
);
```
...
...
@@ -731,16 +775,18 @@ removeAll(userId: number): Promise\<void>
**示例:**
```
js
function
removeAllCallback
(
err
)
{
if
(
err
)
{
console
.
error
(
`removeAll failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
removeAll success
"
);
}
```
ts
import
Base
from
'
@ohos.base
'
;
let
removeAllCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`removeAll failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
removeAll success
"
);
}
}
let
userId
=
1
;
let
userId
:
number
=
1
;
notificationSubscribe
.
removeAll
(
userId
,
removeAllCallback
);
```
...
...
zh-cn/application-dev/reference/apis/js-apis-system-notification.md
浏览文件 @
90773e5a
...
...
@@ -51,11 +51,7 @@ show(options?: ShowNotificationOptions): void
**示例:**
```
ts
class
NotificationClass
{
show
:
Function
}
let
notificationObj
:
NotificationClass
=
{
let
notificationObj
:
notification
=
{
show
()
{
notification
.
show
({
contentTitle
:
'
title info
'
,
...
...
@@ -69,5 +65,5 @@ let notificationObj: NotificationClass = {
}
}
export
default
notificationObj
export
default
notificationObj
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录