Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
b1f95d17
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看板
未验证
提交
b1f95d17
编写于
8月 29, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 29, 2023
浏览文件
操作
浏览文件
下载
差异文件
!23400 元能力ArkTs整改
Merge pull request !23400 from xuzhihao/master
上级
c479624c
0b40c937
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
507 addition
and
399 deletion
+507
-399
en/application-dev/application-models/arkts-ui-widget-event-formextensionability.md
...tion-models/arkts-ui-widget-event-formextensionability.md
+5
-8
en/application-dev/reference/apis/js-apis-app-form-formBindingData.md
...on-dev/reference/apis/js-apis-app-form-formBindingData.md
+8
-5
en/application-dev/reference/apis/js-apis-system-notification.md
...ication-dev/reference/apis/js-apis-system-notification.md
+19
-13
zh-cn/application-dev/application-models/arkts-ui-widget-event-formextensionability.md
...tion-models/arkts-ui-widget-event-formextensionability.md
+5
-8
zh-cn/application-dev/reference/apis/js-apis-app-form-formBindingData.md
...on-dev/reference/apis/js-apis-app-form-formBindingData.md
+11
-6
zh-cn/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md
...v/reference/apis/js-apis-app-form-formExtensionAbility.md
+35
-19
zh-cn/application-dev/reference/apis/js-apis-app-form-formHost.md
...plication-dev/reference/apis/js-apis-app-form-formHost.md
+100
-92
zh-cn/application-dev/reference/apis/js-apis-app-form-formProvider.md
...ation-dev/reference/apis/js-apis-app-form-formProvider.md
+69
-35
zh-cn/application-dev/reference/apis/js-apis-application-formBindingData.md
...dev/reference/apis/js-apis-application-formBindingData.md
+7
-5
zh-cn/application-dev/reference/apis/js-apis-application-formHost.md
...cation-dev/reference/apis/js-apis-application-formHost.md
+92
-85
zh-cn/application-dev/reference/apis/js-apis-application-formProvider.md
...on-dev/reference/apis/js-apis-application-formProvider.md
+29
-12
zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md
...ce/apis/js-apis-inner-application-formExtensionContext.md
+107
-97
zh-cn/application-dev/reference/apis/js-apis-inner-application-missionSnapshot.md
...ference/apis/js-apis-inner-application-missionSnapshot.md
+1
-1
zh-cn/application-dev/reference/apis/js-apis-system-notification.md
...ication-dev/reference/apis/js-apis-system-notification.md
+19
-13
未找到文件。
en/application-dev/application-models/arkts-ui-widget-event-formextensionability.md
浏览文件 @
b1f95d17
...
...
@@ -48,21 +48,18 @@ On the widget page, the **postCardAction** API can be used to trigger a message
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
,
message
)
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// Called when a specified message event defined by the form provider is triggered.
console
.
info
(
`FormAbility onEvent, formId =
${
formId
}
, message:
${
JSON
.
stringify
(
message
)}
`
);
let
formData
=
{
'
title
'
:
'
Title Update.
'
,
// It matches the widget layout.
'
detail
'
:
'
Description update success.
'
,
// It matches the widget layout.
};
let
formData
=
new
Map
<
Object
,
string
>
();
formData
.
set
(
'
title
'
,
'
Title Update.
'
);
// It matches the widget layout.
formData
.
set
(
'
detail
'
,
'
Description update success.
'
);
// It matches the widget layout.
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
));
})
}
...
}
```
...
...
en/application-dev/reference/apis/js-apis-app-form-formBindingData.md
浏览文件 @
b1f95d17
...
...
@@ -66,11 +66,14 @@ import fs from '@ohos.file.fs';
try
{
let
fd
=
fs
.
openSync
(
'
/path/to/form.png
'
);
let
obj
=
{
'
temperature
'
:
'
21°
'
,
'
formImages
'
:
{
'
image
'
:
fd
}
};
formBindingData
.
createFormBindingData
(
obj
);
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
)
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
en/application-dev/reference/apis/js-apis-system-notification.md
浏览文件 @
b1f95d17
...
...
@@ -50,18 +50,24 @@ Displays a notification.
| options | ShowNotificationOptions | No| Notification title.|
**Example**
```
javascript
export
default
{
show
()
{
notification
.
show
({
contentTitle
:
'
title info
'
,
contentText
:
'
text
'
,
clickAction
:
{
bundleName
:
'
com.example.testapp
'
,
abilityName
:
'
notificationDemo
'
,
uri
:
'
/path/to/notification
'
}
});
}
```
ts
class
NotificationClass
{
show
:
Function
}
let
notificationObj
:
NotificationClass
=
{
show
()
{
notification
.
show
({
contentTitle
:
'
title info
'
,
contentText
:
'
text
'
,
clickAction
:
{
bundleName
:
'
com.example.testapp
'
,
abilityName
:
'
notificationDemo
'
,
uri
:
'
/path/to/notification
'
}
});
}
}
export
default
notificationObj
```
zh-cn/application-dev/application-models/arkts-ui-widget-event-formextensionability.md
浏览文件 @
b1f95d17
...
...
@@ -46,21 +46,18 @@
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
,
message
)
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// Called when a specified message event defined by the form provider is triggered.
console
.
info
(
`FormAbility onEvent, formId =
${
formId
}
, message:
${
JSON
.
stringify
(
message
)}
`
);
let
formData
=
{
'
title
'
:
'
Title Update.
'
,
// 和卡片布局中对应
'
detail
'
:
'
Description update success.
'
,
// 和卡片布局中对应
};
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
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
FormAbility updateForm failed:
'
+
JSON
.
stringify
(
error
));
})
}
...
}
```
...
...
zh-cn/application-dev/reference/apis/js-apis-app-form-formBindingData.md
浏览文件 @
b1f95d17
...
...
@@ -66,12 +66,17 @@ import fs from '@ohos.file.fs';
try
{
let
fd
=
fs
.
openSync
(
'
/path/to/form.png
'
);
let
obj
=
{
'
temperature
'
:
'
21°
'
,
'
formImages
'
:
{
'
image
'
:
fd
}
};
formBindingData
.
createFormBindingData
(
obj
);
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
)
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
let
code
=
(
error
as
Base
.
BusinessError
).
code
;
let
message
=
(
error
as
Base
.
BusinessError
).
message
;
console
.
error
(
`catch error, code:
${
code
}
, message:
${
message
}
`
);
}
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md
浏览文件 @
b1f95d17
...
...
@@ -46,18 +46,19 @@ onAddForm(want: Want): formBindingData.FormBindingData
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onAddForm
(
want
)
{
onAddForm
(
want
:
Want
)
{
console
.
log
(
`FormExtensionAbility onAddForm, want:
${
want
.
abilityName
}
`
);
let
dataObj1
=
{
temperature
:
'
11c
'
,
'
time
'
:
'
11:00
'
};
let
dataObj1
=
new
Map
<
Object
,
string
>
();
dataObj1
.
set
(
'
temperature
'
,
'
11c
'
);
dataObj1
.
set
(
'
time
'
,
'
11:00
'
);
let
obj1
=
formBindingData
.
createFormBindingData
(
dataObj1
);
return
obj1
;
}
}
;
}
```
## onCastToNormalForm
...
...
@@ -80,7 +81,7 @@ onCastToNormalForm(formId: string): void
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onCastToNormalForm
(
formId
)
{
onCastToNormalForm
(
formId
:
string
)
{
console
.
log
(
`FormExtensionAbility onCastToNormalForm, formId:
${
formId
}
`
);
}
};
...
...
@@ -108,16 +109,18 @@ import formBindingData from '@ohos.app.form.formBindingData';
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onUpdateForm
(
formId
)
{
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
)
=>
{
console
.
error
(
`Operation updateForm failed. Cause:
${
error
}
`
);
});
}
};
...
...
@@ -144,13 +147,24 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
// 由于arkTs中无Object.keys,且无法使用for..in...
// 若报arkTs问题,请将此方法单独抽离至一个ts文件中并暴露,在需要用到的ets文件中引入使用
function
getObjKeys
(
obj
:
Object
):
string
[]
{
let
keys
=
Object
.
keys
(
obj
);
return
keys
;
}
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onChangeFormVisibility
(
newStatus
)
{
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
]}
`
);
...
...
@@ -185,7 +199,7 @@ onFormEvent(formId: string, message: string): void
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
,
message
)
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
console
.
log
(
`FormExtensionAbility onFormEvent, formId:
${
formId
}
, message:
${
message
}
`
);
}
};
...
...
@@ -211,7 +225,7 @@ onRemoveForm(formId: string): void
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onRemoveForm
(
formId
)
{
onRemoveForm
(
formId
:
string
)
{
console
.
log
(
`FormExtensionAbility onRemoveForm, formId:
${
formId
}
`
);
}
};
...
...
@@ -235,9 +249,10 @@ onConfigurationUpdate(newConfig: Configuration): void;
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
{
Configuration
}
from
'
@ohos.app.ability.Configuration
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onConfigurationUpdate
(
config
)
{
onConfigurationUpdate
(
config
:
Configuration
)
{
console
.
log
(
`onConfigurationUpdate, config:
${
JSON
.
stringify
(
config
)}
`
);
}
};
...
...
@@ -262,9 +277,10 @@ onAcquireFormState?(want: Want): formInfo.FormState;
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onAcquireFormState
(
want
)
{
onAcquireFormState
(
want
:
Want
)
{
console
.
log
(
`FormExtensionAbility onAcquireFormState, want:
${
want
}
`
);
return
formInfo
.
FormState
.
UNKNOWN
;
}
...
...
@@ -299,11 +315,11 @@ onShareForm?(formId: string): { [key: string]: Object }
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onShareForm
(
formId
)
{
onShareForm
(
formId
:
string
)
{
console
.
log
(
`FormExtensionAbility onShareForm, formId:
${
formId
}
`
);
let
wantParams
=
{
'
temperature
'
:
'
20
'
,
'
time
'
:
'
2022-8-8 09:59
'
,
'
time
'
:
'
2022-8-8 09:59
'
,
s
};
return
wantParams
;
}
...
...
@@ -338,7 +354,7 @@ onAcquireFormData?(formId: string): { [key: string]: Object }
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onAcquireFormData
(
formId
)
{
onAcquireFormData
(
formId
:
string
)
{
console
.
log
(
'
FormExtensionAbility onAcquireFormData, formId: ${formId}
'
);
let
wantParams
=
{
'
temperature
'
:
'
20
'
,
...
...
zh-cn/application-dev/reference/apis/js-apis-app-form-formHost.md
浏览文件 @
b1f95d17
...
...
@@ -11,6 +11,7 @@ formHost模块提供了卡片使用方相关接口的能力,包括对使用方
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
import
Base
from
'
@ohos.base
'
;
```
## deleteForm
...
...
@@ -51,8 +52,8 @@ deleteForm(formId: string, callback: AsyncCallback<void>): void
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
'
12400633174999288
'
;
formHost
.
deleteForm
(
formId
,
(
error
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
deleteForm
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
else
{
...
...
@@ -108,11 +109,11 @@ deleteForm(formId: string): Promise<void>
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
deleteForm
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost deleteForm success
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost deleteForm, error: ${JSON.stringify(error)}
'
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
...
...
@@ -157,8 +158,8 @@ releaseForm(formId: string, callback: AsyncCallback<void>): void
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
(
error
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -207,8 +208,8 @@ releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback<
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
true
,
(
error
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
true
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -262,10 +263,10 @@ releaseForm(formId: string, isReleaseCache?: boolean): Promise<void>
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
true
).
then
(()
=>
{
console
.
log
(
'
formHost releaseForm success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -311,8 +312,8 @@ requestForm(formId: string, callback: AsyncCallback<void>): void
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
'
12400633174999288
'
;
formHost
.
requestForm
(
formId
,
(
error
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
requestForm
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -365,10 +366,10 @@ requestForm(formId: string): Promise<void>
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
requestForm
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost requestForm success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -415,8 +416,8 @@ castToNormalForm(formId: string, callback: AsyncCallback<void>): void
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
'
12400633174999288
'
;
formHost
.
castToNormalForm
(
formId
,
(
error
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
castToNormalForm
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -469,10 +470,10 @@ castToNormalForm(formId: string): Promise<void>
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
castToNormalForm
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost castTempForm success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -516,8 +517,8 @@ notifyVisibleForms(formIds: Array<string>, callback: AsyncCallback<void
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
[
'
12400633174999288
'
];
formHost
.
notifyVisibleForms
(
formId
,
(
error
)
=>
{
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyVisibleForms
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -568,10 +569,10 @@ notifyVisibleForms(formIds: Array<string>): Promise<void>
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
[
'
12400633174999288
'
];
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyVisibleForms
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost notifyVisibleForms success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -615,8 +616,8 @@ notifyInvisibleForms(formIds: Array<string>, callback: AsyncCallback<vo
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
[
'
12400633174999288
'
];
formHost
.
notifyInvisibleForms
(
formId
,
(
error
)
=>
{
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyInvisibleForms
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -667,10 +668,10 @@ notifyInvisibleForms(formIds: Array<string>): Promise<void>
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
[
'
12400633174999288
'
];
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyInvisibleForms
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost notifyInvisibleForms success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -715,8 +716,8 @@ enableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void&
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
[
'
12400633174999288
'
];
formHost
.
enableFormsUpdate
(
formId
,
(
error
)
=>
{
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
enableFormsUpdate
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -768,10 +769,10 @@ enableFormsUpdate(formIds: Array<string>): Promise<void>
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
[
'
12400633174999288
'
];
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
enableFormsUpdate
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost enableFormsUpdate success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -817,8 +818,8 @@ disableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
[
'
12400633174999288
'
];
formHost
.
disableFormsUpdate
(
formId
,
(
error
)
=>
{
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
disableFormsUpdate
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -871,10 +872,10 @@ disableFormsUpdate(formIds: Array<string>): Promise<void>
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formId
=
[
'
12400633174999288
'
];
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
disableFormsUpdate
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost disableFormsUpdate success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -911,7 +912,7 @@ isSystemReady(callback: AsyncCallback<void>): void
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
formHost
.
isSystemReady
((
error
,
data
)
=>
{
formHost
.
isSystemReady
((
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -951,7 +952,7 @@ import formHost from '@ohos.app.form.formHost';
try
{
formHost
.
isSystemReady
().
then
(()
=>
{
console
.
log
(
'
formHost isSystemReady success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -992,13 +993,14 @@ getAllFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>):
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
try
{
formHost
.
getAllFormsInfo
((
error
,
data
)
=>
{
formHost
.
getAllFormsInfo
((
error
:
Base
.
BusinessError
,
data
:
formInfo
.
FormInfo
[]
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
else
{
console
.
log
(
'
formHost getAllFormsInfo, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formHost getAllFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
}
});
}
catch
(
error
)
{
...
...
@@ -1038,11 +1040,12 @@ getAllFormsInfo(): Promise<Array<formInfo.FormInfo>>
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
try
{
formHost
.
getAllFormsInfo
().
then
((
data
)
=>
{
console
.
log
(
'
formHost getAllFormsInfo data: ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
formHost
.
getAllFormsInfo
().
then
((
data
:
formInfo
.
FormInfo
[]
)
=>
{
console
.
log
(
`formHost getAllFormsInfo data:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1085,13 +1088,14 @@ getFormsInfo(bundleName: string, callback: AsyncCallback<Array<formInfo.Fo
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
try
{
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
(
error
,
data
)
=>
{
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
(
error
:
Base
.
BusinessError
,
data
:
formInfo
.
FormInfo
[]
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
else
{
console
.
log
(
'
formHost getFormsInfo, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formHost getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
}
});
}
catch
(
error
)
{
...
...
@@ -1135,9 +1139,10 @@ getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback<
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
try
{
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
'
entry
'
,
(
error
,
data
)
=>
{
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
'
entry
'
,
(
error
:
Base
.
BusinessError
,
data
:
formInfo
.
FormInfo
[]
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
else
{
...
...
@@ -1190,11 +1195,12 @@ getFormsInfo(bundleName: string, moduleName?: string): Promise<Array<formI
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
try
{
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
'
entry
'
).
then
((
data
)
=>
{
console
.
log
(
'
formHost getFormsInfo, data: ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
'
entry
'
).
then
((
data
:
formInfo
.
FormInfo
[]
)
=>
{
console
.
log
(
`formHost getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1238,12 +1244,12 @@ deleteInvalidForms(formIds: Array<string>, callback: AsyncCallback<numb
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
deleteInvalidForms
(
formIds
,
(
error
,
data
)
=>
{
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
deleteInvalidForms
(
formIds
,
(
error
:
Base
.
BusinessError
,
data
:
number
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
else
{
console
.
log
(
'
formHost deleteInvalidForms, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formHost deleteInvalidForms, data:
${
JSON
.
stringify
(
data
)}
`
);
}
});
}
catch
(
error
)
{
...
...
@@ -1292,10 +1298,10 @@ deleteInvalidForms(formIds: Array<string>): Promise<number>
import
formHost
from
'
@ohos.app.form.formHost
'
;
try
{
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
deleteInvalidForms
(
formIds
).
then
((
data
)
=>
{
console
.
log
(
'
formHost deleteInvalidForms, data: ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
deleteInvalidForms
(
formIds
).
then
((
data
:
number
)
=>
{
console
.
log
(
`formHost deleteInvalidForms, data:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1338,8 +1344,10 @@ acquireFormState(want: Want, callback: AsyncCallback<formInfo.FormStateInfo&g
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
let
want
=
{
let
want
:
Want
=
{
'
deviceId
'
:
''
,
'
bundleName
'
:
'
ohos.samples.FormApplication
'
,
'
abilityName
'
:
'
FormAbility
'
,
...
...
@@ -1350,11 +1358,11 @@ let want = {
}
};
try
{
formHost
.
acquireFormState
(
want
,
(
error
,
data
)
=>
{
formHost
.
acquireFormState
(
want
,
(
error
:
Base
.
BusinessError
,
data
:
formInfo
.
FormStateInfo
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
else
{
console
.
log
(
'
formHost acquireFormState, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formHost acquireFormState, data:
${
JSON
.
stringify
(
data
)}
`
);
}
});
}
catch
(
error
)
{
...
...
@@ -1402,8 +1410,10 @@ acquireFormState(want: Want): Promise<formInfo.FormStateInfo>
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
let
want
=
{
let
want
:
Want
=
{
'
deviceId
'
:
''
,
'
bundleName
'
:
'
ohos.samples.FormApplication
'
,
'
abilityName
'
:
'
FormAbility
'
,
...
...
@@ -1414,9 +1424,9 @@ let want = {
}
};
try
{
formHost
.
acquireFormState
(
want
).
then
((
data
)
=>
{
console
.
log
(
'
formHost acquireFormState, data: ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
formHost
.
acquireFormState
(
want
).
then
((
data
:
formInfo
.
FormStateInfo
)
=>
{
console
.
log
(
`formHost acquireFormState, data:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1453,10 +1463,9 @@ on(type: 'formUninstall', callback: Callback<string>): void
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
callback
=
function
(
formId
)
{
console
.
log
(
'
formHost on formUninstall, formId: ${formId}
'
);
}
formHost
.
on
(
'
formUninstall
'
,
callback
);
formHost
.
on
(
'
formUninstall
'
,
(
formId
:
string
)
=>
{
console
.
log
(
`formHost on formUninstall, formId:
${
formId
}
`
);
});
```
## off('formUninstall')
...
...
@@ -1488,10 +1497,9 @@ off(type: 'formUninstall', callback?: Callback<string>): void
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
callback
=
function
(
formId
)
{
console
.
log
(
'
formHost on formUninstall, formId: ${formId}
'
);
}
formHost
.
off
(
'
formUninstall
'
,
callback
);
formHost
.
off
(
'
formUninstall
'
,
(
formId
:
string
)
=>
{
console
.
log
(
`formHost on formUninstall, formId:
${
formId
}
`
);
});
```
## notifyFormsVisible
...
...
@@ -1531,9 +1539,9 @@ notifyFormsVisible(formIds: Array<string>, isVisible: boolean, callback: A
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
try
{
formHost
.
notifyFormsVisible
(
formIds
,
true
,
(
error
)
=>
{
formHost
.
notifyFormsVisible
(
formIds
,
true
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -1585,11 +1593,11 @@ notifyFormsVisible(formIds: Array<string>, isVisible: boolean): Promise<
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
try
{
formHost
.
notifyFormsVisible
(
formIds
,
true
).
then
(()
=>
{
console
.
log
(
'
formHost notifyFormsVisible success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1634,9 +1642,9 @@ notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean, c
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
try
{
formHost
.
notifyFormsEnableUpdate
(
formIds
,
true
,
(
error
)
=>
{
formHost
.
notifyFormsEnableUpdate
(
formIds
,
true
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -1688,11 +1696,11 @@ notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean):
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
try
{
formHost
.
notifyFormsEnableUpdate
(
formIds
,
true
).
then
(()
=>
{
console
.
log
(
'
formHost notifyFormsEnableUpdate success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1736,10 +1744,10 @@ shareForm(formId: string, deviceId: string, callback: AsyncCallback<void>)
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
deviceId
=
'
EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2
'
;
let
formId
:
string
=
'
12400633174999288
'
;
let
deviceId
:
string
=
'
EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2
'
;
try
{
formHost
.
shareForm
(
formId
,
deviceId
,
(
error
)
=>
{
formHost
.
shareForm
(
formId
,
deviceId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -1791,12 +1799,12 @@ shareForm(formId: string, deviceId: string): Promise<void>
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
deviceId
=
'
EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2
'
;
let
formId
:
string
=
'
12400633174999288
'
;
let
deviceId
:
string
=
'
EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2
'
;
try
{
formHost
.
shareForm
(
formId
,
deviceId
).
then
(()
=>
{
console
.
log
(
'
formHost shareForm success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1840,9 +1848,9 @@ notifyFormsPrivacyProtected(formIds: Array\<string>, isProtected: boolean, callb
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
try
{
formHost
.
notifyFormsPrivacyProtected
(
formIds
,
true
,
(
error
)
=>
{
formHost
.
notifyFormsPrivacyProtected
(
formIds
,
true
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
...
...
@@ -1891,11 +1899,11 @@ notifyFormsPrivacyProtected(formIds: Array\<string\>, isProtected: boolean): Pro
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
try
{
formHost
.
notifyFormsPrivacyProtected
(
formIds
,
true
).
then
(()
=>
{
console
.
log
(
'
formHost notifyFormsPrivacyProtected success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1937,13 +1945,13 @@ acquireFormData(formId: string, callback: AsyncCallback<{[key: string]: Object}>
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
try
{
formHost
.
acquireFormData
(
formId
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
else
{
console
.
log
(
'
formHost acquireFormData, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formHost acquireFormData, data:
${
JSON
.
stringify
(
data
)}
`
);
}
});
}
catch
(
error
)
{
...
...
@@ -1989,11 +1997,11 @@ acquireFormData(formId: string): Promise<{[key: string]: Object}>;
```
ts
import
formHost
from
'
@ohos.app.form.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
try
{
formHost
.
acquireFormData
(
formId
).
then
((
data
)
=>
{
console
.
log
(
'
formHost acquireFormData success
'
+
data
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
...
...
zh-cn/application-dev/reference/apis/js-apis-app-form-formProvider.md
浏览文件 @
b1f95d17
...
...
@@ -9,6 +9,7 @@ FormProvider模块提供了卡片提供方相关接口的能力,开发者在
```
ts
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
Base
from
'
@ohos.base
'
;
```
## setFormNextRefreshTime
...
...
@@ -45,9 +46,9 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l
**示例:**
```
ts
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
try
{
formProvider
.
setFormNextRefreshTime
(
formId
,
5
,
(
error
)
=>
{
formProvider
.
setFormNextRefreshTime
(
formId
,
5
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
return
;
...
...
@@ -98,11 +99,11 @@ setFormNextRefreshTime(formId: string, minute: number): Promise<void>
**示例:**
```
ts
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
try
{
formProvider
.
setFormNextRefreshTime
(
formId
,
5
).
then
(()
=>
{
console
.
log
(
`formProvider setFormNextRefreshTime success`
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
...
...
@@ -145,10 +146,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
try
{
let
obj
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
updateForm
(
formId
,
obj
,
(
error
)
=>
{
class
createFormBindingDataParamType
{
temperature
:
string
time
:
string
}
let
createFormBindingDataParam
:
createFormBindingDataParamType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
formProvider
.
updateForm
(
formId
,
obj
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
return
;
...
...
@@ -200,12 +209,20 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
let
formId
=
'
12400633174999288
'
;
let
obj
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
let
formId
:
string
=
'
12400633174999288
'
;
class
createFormBindingDataParamType
{
temperature
:
string
time
:
string
}
let
createFormBindingDataParam
:
createFormBindingDataParamType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
try
{
formProvider
.
updateForm
(
formId
,
obj
).
then
(()
=>
{
console
.
log
(
`formProvider updateForm success`
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
...
...
@@ -247,7 +264,7 @@ try {
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
return
;
}
console
.
log
(
'
formProvider getFormsInfo, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formProvider getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
...
...
@@ -294,7 +311,7 @@ try {
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
return
;
}
console
.
log
(
'
formProvider getFormsInfo, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formProvider getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
...
...
@@ -342,9 +359,9 @@ const filter: formInfo.FormInfoFilter = {
moduleName
:
'
entry
'
};
try
{
formProvider
.
getFormsInfo
(
filter
).
then
((
data
)
=>
{
console
.
log
(
'
formProvider getFormsInfo, data: ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
formProvider
.
getFormsInfo
(
filter
).
then
((
data
:
formInfo
.
FormInfo
[]
)
=>
{
console
.
log
(
`formProvider getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
...
...
@@ -386,8 +403,9 @@ requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData,
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
let
want
=
{
let
want
:
Want
=
{
abilityName
:
'
FormAbility
'
,
parameters
:
{
'
ohos.extra.param.key.form_dimension
'
:
2
,
...
...
@@ -396,8 +414,16 @@ let want = {
}
};
try
{
let
obj
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
requestPublishForm
(
want
,
obj
,
(
error
,
data
)
=>
{
class
createFormBindingDataParamType
{
temperature
:
string
time
:
string
}
let
createFormBindingDataParam
:
createFormBindingDataParamType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
formProvider
.
requestPublishForm
(
want
,
obj
,
(
error
:
Base
.
BusinessError
,
data
:
string
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
return
;
...
...
@@ -441,7 +467,9 @@ requestPublishForm(want: Want, callback: AsyncCallback<string>): void
**示例:**
```
ts
let
want
=
{
import
Want
from
'
@ohos.app.ability.Want
'
;
let
want
:
Want
=
{
abilityName
:
'
FormAbility
'
,
parameters
:
{
'
ohos.extra.param.key.form_dimension
'
:
2
,
...
...
@@ -450,12 +478,12 @@ let want = {
}
};
try
{
formProvider
.
requestPublishForm
(
want
,
(
error
,
data
)
=>
{
formProvider
.
requestPublishForm
(
want
,
(
error
:
Base
.
BusinessError
,
data
:
string
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
return
;
}
console
.
log
(
'
formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}
'
);
console
.
log
(
`formProvider requestPublishForm, form ID is:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
...
...
@@ -500,7 +528,9 @@ requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData
**示例:**
```
ts
let
want
=
{
import
Want
from
'
@ohos.app.ability.Want
'
;
let
want
:
Want
=
{
abilityName
:
'
FormAbility
'
,
parameters
:
{
'
ohos.extra.param.key.form_dimension
'
:
2
,
...
...
@@ -509,9 +539,9 @@ let want = {
}
};
try
{
formProvider
.
requestPublishForm
(
want
).
then
((
data
)
=>
{
console
.
log
(
'
formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
formProvider
.
requestPublishForm
(
want
).
then
((
data
:
string
)
=>
{
console
.
log
(
`formProvider requestPublishForm success, form ID is :
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
...
...
@@ -549,13 +579,15 @@ isRequestPublishFormSupported(callback: AsyncCallback<boolean>): void
**示例:**
```
ts
import
Want
from
'
@ohos.app.ability.Want
'
;
try
{
formProvider
.
isRequestPublishFormSupported
((
error
,
isSupported
)
=>
{
formProvider
.
isRequestPublishFormSupported
((
error
:
Base
.
BusinessError
,
isSupported
:
boolean
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
}
else
{
if
(
isSupported
)
{
var
w
ant
=
{
let
want
:
W
ant
=
{
abilityName
:
'
FormAbility
'
,
parameters
:
{
'
ohos.extra.param.key.form_dimension
'
:
2
,
...
...
@@ -564,12 +596,12 @@ try {
}
};
try
{
formProvider
.
requestPublishForm
(
want
,
(
error
,
data
)
=>
{
formProvider
.
requestPublishForm
(
want
,
(
error
:
Base
.
BusinessError
,
data
:
string
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
return
;
}
console
.
log
(
'
formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}
'
);
console
.
log
(
`formProvider requestPublishForm, form ID is:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
...
...
@@ -611,10 +643,12 @@ isRequestPublishFormSupported(): Promise<boolean>
**示例:**
```
ts
import
Want
from
'
@ohos.app.ability.Want
'
;
try
{
formProvider
.
isRequestPublishFormSupported
().
then
((
isSupported
)
=>
{
formProvider
.
isRequestPublishFormSupported
().
then
((
isSupported
:
boolean
)
=>
{
if
(
isSupported
)
{
var
w
ant
=
{
let
want
:
W
ant
=
{
abilityName
:
'
FormAbility
'
,
parameters
:
{
'
ohos.extra.param.key.form_dimension
'
:
2
,
...
...
@@ -623,16 +657,16 @@ try {
}
};
try
{
formProvider
.
requestPublishForm
(
want
).
then
((
data
)
=>
{
console
.
log
(
'
formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
formProvider
.
requestPublishForm
(
want
).
then
((
data
:
string
)
=>
{
console
.
log
(
`formProvider requestPublishForm success, form ID is :
${
JSON
.
stringify
(
data
)}
`
);
}).
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
}
)`
);
}
}
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
...
...
zh-cn/application-dev/reference/apis/js-apis-application-formBindingData.md
浏览文件 @
b1f95d17
...
...
@@ -53,11 +53,13 @@ import fs from '@ohos.file.fs';
try
{
let
fd
=
fs
.
openSync
(
'
/path/to/form.png
'
);
let
obj
=
{
'
temperature
'
:
'
21°
'
,
'
formImages
'
:
{
'
image
'
:
fd
}
};
formBindingData
.
createFormBindingData
(
obj
);
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
);
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
}
catch
(
error
)
{
console
.
error
(
'
catch error, error: ${JSON.stringify(error)}
'
);
}
...
...
zh-cn/application-dev/reference/apis/js-apis-application-formHost.md
浏览文件 @
b1f95d17
...
...
@@ -12,6 +12,7 @@ formHost模块提供了卡片使用方相关接口的能力,包括对使用方
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
import
Base
from
'
@ohos.base
'
;
```
## deleteForm
...
...
@@ -36,7 +37,7 @@ deleteForm(formId: string, callback: AsyncCallback<void>): void
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
deleteForm
(
formId
,
(
error
,
data
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost deleteForm, error: ${JSON.stringify(error)}
'
);
...
...
@@ -71,10 +72,10 @@ deleteForm(formId: string): Promise<void>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
deleteForm
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost deleteForm success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost deleteForm, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -101,8 +102,8 @@ releaseForm(formId: string, callback: AsyncCallback<void>): void
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
(
error
,
data
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost releaseForm, error: ${JSON.stringify(error)}
'
);
}
else
{
...
...
@@ -134,8 +135,8 @@ releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback<
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
true
,
(
error
,
data
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
true
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost releaseForm, error: ${JSON.stringify(error)}
'
);
}
else
{
...
...
@@ -172,10 +173,10 @@ releaseForm(formId: string, isReleaseCache?: boolean): Promise<void>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
releaseForm
(
formId
,
true
).
then
(()
=>
{
console
.
log
(
'
formHost releaseForm success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost releaseForm, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -202,8 +203,8 @@ requestForm(formId: string, callback: AsyncCallback<void>): void
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
formHost
.
requestForm
(
formId
,
(
error
,
data
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
requestForm
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost requestForm, error: ${JSON.stringify(error)}
'
);
}
...
...
@@ -237,10 +238,10 @@ requestForm(formId: string): Promise<void>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
requestForm
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost requestForm success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost requestForm, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -267,8 +268,8 @@ castTempForm(formId: string, callback: AsyncCallback<void>): void
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
formHost
.
castTempForm
(
formId
,
(
error
,
data
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
castTempForm
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost castTempForm, error: ${JSON.stringify(error)}
'
);
}
...
...
@@ -302,10 +303,10 @@ castTempForm(formId: string): Promise<void>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
castTempForm
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost castTempForm success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost castTempForm, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -332,8 +333,8 @@ notifyVisibleForms(formIds: Array<string>, callback: AsyncCallback<void
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
[
'
12400633174999288
'
];
formHost
.
notifyVisibleForms
(
formId
,
(
error
,
data
)
=>
{
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyVisibleForms
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost notifyVisibleForms, error: ${JSON.stringify(error)}
'
);
}
...
...
@@ -367,10 +368,10 @@ notifyVisibleForms(formIds: Array<string>): Promise<void>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
[
'
12400633174999288
'
];
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyVisibleForms
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost notifyVisibleForms success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost notifyVisibleForms, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -397,8 +398,8 @@ notifyInvisibleForms(formIds: Array<string>, callback: AsyncCallback<vo
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
[
'
12400633174999288
'
];
formHost
.
notifyInvisibleForms
(
formId
,
(
error
,
data
)
=>
{
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyInvisibleForms
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost notifyInvisibleForms, error: ${JSON.stringify(error)}
'
);
}
...
...
@@ -432,10 +433,10 @@ notifyInvisibleForms(formIds: Array<string>): Promise<void>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
[
'
12400633174999288
'
];
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyInvisibleForms
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost notifyInvisibleForms success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost notifyInvisibleForms, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -462,8 +463,8 @@ enableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void&
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
[
'
12400633174999288
'
];
formHost
.
enableFormsUpdate
(
formId
,
(
error
,
data
)
=>
{
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
enableFormsUpdate
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost enableFormsUpdate, error: ${JSON.stringify(error)}
'
);
}
...
...
@@ -497,10 +498,10 @@ enableFormsUpdate(formIds: Array<string>): Promise<void>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
[
'
12400633174999288
'
];
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
enableFormsUpdate
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost enableFormsUpdate success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost enableFormsUpdate, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -527,8 +528,8 @@ disableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
[
'
12400633174999288
'
];
formHost
.
disableFormsUpdate
(
formId
,
(
error
,
data
)
=>
{
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
disableFormsUpdate
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost disableFormsUpdate, error: ${JSON.stringify(error)}
'
);
}
...
...
@@ -562,10 +563,10 @@ disableFormsUpdate(formIds: Array<string>): Promise<void>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
[
'
12400633174999288
'
];
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
disableFormsUpdate
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost disableFormsUpdate success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost disableFormsUpdate, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -589,8 +590,8 @@ isSystemReady(callback: AsyncCallback<void>): void
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
formHost
.
isSystemReady
((
error
,
data
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
isSystemReady
((
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost isSystemReady, error: ${JSON.stringify(error)}
'
);
}
...
...
@@ -616,10 +617,10 @@ isSystemReady(): Promise<void>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
isSystemReady
().
then
(()
=>
{
console
.
log
(
'
formHost isSystemReady success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost isSystemReady, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -644,8 +645,9 @@ getAllFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>):
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
formHost
.
getAllFormsInfo
((
error
,
data
)
=>
{
formHost
.
getAllFormsInfo
((
error
:
Base
.
BusinessError
,
data
:
formInfo
.
FormInfo
[]
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost getAllFormsInfo, error: ${JSON.stringify(error)}
'
);
}
else
{
...
...
@@ -674,10 +676,11 @@ getAllFormsInfo(): Promise<Array<formInfo.FormInfo>>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
formHost
.
getAllFormsInfo
().
then
((
data
)
=>
{
formHost
.
getAllFormsInfo
().
then
((
data
:
formInfo
.
FormInfo
[]
)
=>
{
console
.
log
(
'
formHost getAllFormsInfo data: ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost getAllFormsInfo, error: ${JSON.stringify(error)}
'
);
});
```
...
...
@@ -703,12 +706,13 @@ getFormsInfo(bundleName: string, callback: AsyncCallback<Array<formInfo.Fo
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
(
error
,
data
)
=>
{
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
(
error
:
Base
.
BusinessError
,
data
:
formInfo
.
FormInfo
[]
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost getFormsInfo, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost getFormsInfo, error:
${
JSON
.
stringify
(
error
)}
`
);
}
else
{
console
.
log
(
'
formHost getFormsInfo, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formHost getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
}
});
```
...
...
@@ -735,8 +739,9 @@ getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback<
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
'
entry
'
,
(
error
,
data
)
=>
{
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
'
entry
'
,
(
error
:
Base
.
BusinessError
,
data
:
formInfo
.
FormInfo
[]
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost getFormsInfo, error: ${JSON.stringify(error)}
'
);
}
else
{
...
...
@@ -773,10 +778,10 @@ getFormsInfo(bundleName: string, moduleName?: string): Promise<Array<formI
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
'
entry
'
).
then
((
data
)
=>
{
console
.
log
(
'
formHost getFormsInfo, data: ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
formHost getFormsInfo, error: ${JSON.stringify(error)}
'
);
formHost
.
getFormsInfo
(
'
com.example.ohos.formjsdemo
'
,
'
entry
'
).
then
((
data
:
formInfo
.
FormInfo
[]
)
=>
{
console
.
log
(
`formHost getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`formHost getFormsInfo, error:
${
JSON
.
stringify
(
error
)}
`
);
});
```
...
...
@@ -802,12 +807,12 @@ deleteInvalidForms(formIds: Array<string>, callback: AsyncCallback<numb
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
deleteInvalidForms
(
formIds
,
(
error
,
data
)
=>
{
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
deleteInvalidForms
(
formIds
,
(
error
:
Base
.
BusinessError
,
data
:
number
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost deleteInvalidForms, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost deleteInvalidForms, error:
${
JSON
.
stringify
(
error
)}
`
);
}
else
{
console
.
log
(
'
formHost deleteInvalidForms, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formHost deleteInvalidForms, data:
${
JSON
.
stringify
(
data
)}
`
);
}
});
```
...
...
@@ -839,11 +844,11 @@ deleteInvalidForms(formIds: Array<string>): Promise<number>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
deleteInvalidForms
(
formIds
).
then
((
data
)
=>
{
console
.
log
(
'
formHost deleteInvalidForms, data: ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
formHost deleteInvalidForms, error: ${JSON.stringify(error)}
'
);
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
deleteInvalidForms
(
formIds
).
then
((
data
:
number
)
=>
{
console
.
log
(
`formHost deleteInvalidForms, data:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`formHost deleteInvalidForms, error:
${
JSON
.
stringify
(
error
)}
`
);
});
```
...
...
@@ -868,8 +873,10 @@ acquireFormState(want: Want, callback: AsyncCallback<formInfo.FormStateInfo&g
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
let
want
=
{
let
want
:
Want
=
{
'
deviceId
'
:
''
,
'
bundleName
'
:
'
ohos.samples.FormApplication
'
,
'
abilityName
'
:
'
FormAbility
'
,
...
...
@@ -879,11 +886,11 @@ let want = {
'
ohos.extra.param.key.form_dimension
'
:
2
}
};
formHost
.
acquireFormState
(
want
,
(
error
,
data
)
=>
{
formHost
.
acquireFormState
(
want
,
(
error
:
Base
.
BusinessError
,
data
:
formInfo
.
FormStateInfo
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost acquireFormState, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost acquireFormState, error:
${
JSON
.
stringify
(
error
)}
`
);
}
else
{
console
.
log
(
'
formHost acquireFormState, data: ${JSON.stringify(data)}
'
);
console
.
log
(
`formHost acquireFormState, data:
${
JSON
.
stringify
(
data
)}
`
);
}
});
```
...
...
@@ -914,8 +921,10 @@ acquireFormState(want: Want): Promise<formInfo.FormStateInfo>
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
let
want
=
{
let
want
:
Want
=
{
'
deviceId
'
:
''
,
'
bundleName
'
:
'
ohos.samples.FormApplication
'
,
'
abilityName
'
:
'
FormAbility
'
,
...
...
@@ -925,10 +934,10 @@ let want = {
'
ohos.extra.param.key.form_dimension
'
:
2
}
};
formHost
.
acquireFormState
(
want
).
then
((
data
)
=>
{
console
.
log
(
'
formHost acquireFormState, data: ${JSON.stringify(data)}
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
formHost acquireFormState, error: ${JSON.stringify(error)}
'
);
formHost
.
acquireFormState
(
want
).
then
((
data
:
formInfo
.
FormStateInfo
)
=>
{
console
.
log
(
`formHost acquireFormState, data:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`formHost acquireFormState, error:
${
JSON
.
stringify
(
error
)}
`
);
});
```
...
...
@@ -952,10 +961,9 @@ on(type: 'formUninstall', callback: Callback<string>): void
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
callback
=
function
(
formId
)
{
console
.
log
(
'
formHost on formUninstall, formId: ${formId}
'
);
};
formHost
.
on
(
'
formUninstall
'
,
callback
);
formHost
.
on
(
'
formUninstall
'
,
(
formId
:
string
)
=>
{
console
.
log
(
`formHost on formUninstall, formId:
${
formId
}
`
);
});
```
## off('formUninstall')
...
...
@@ -978,10 +986,9 @@ off(type: 'formUninstall', callback?: Callback<string>): void
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
callback
=
function
(
formId
)
{
console
.
log
(
'
formHost on formUninstall, formId: ${formId}
'
);
};
formHost
.
off
(
'
formUninstall
'
,
callback
);
formHost
.
off
(
'
formUninstall
'
,
(
formId
:
string
)
=>
{
console
.
log
(
`formHost on formUninstall, formId:
${
formId
}
`
);
});
```
## notifyFormsVisible
...
...
@@ -1007,10 +1014,10 @@ notifyFormsVisible(formIds: Array<string>, isVisible: boolean, callback: A
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
notifyFormsVisible
(
formIds
,
true
,
(
error
,
data
)
=>
{
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
notifyFormsVisible
(
formIds
,
true
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost notifyFormsVisible, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost notifyFormsVisible, error:
${
JSON
.
stringify
(
error
)}
`
);
}
});
```
...
...
@@ -1043,11 +1050,11 @@ notifyFormsVisible(formIds: Array<string>, isVisible: boolean): Promise<
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
notifyFormsVisible
(
formIds
,
true
).
then
(()
=>
{
console
.
log
(
'
formHost notifyFormsVisible success
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
formHost notifyFormsVisible, error: ${JSON.stringify(error)}
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`formHost notifyFormsVisible, error:
${
JSON
.
stringify
(
error
)}
`
);
});
```
...
...
@@ -1074,8 +1081,8 @@ notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean, c
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
notifyFormsEnableUpdate
(
formIds
,
true
,
(
error
,
data
)
=>
{
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
notifyFormsEnableUpdate
(
formIds
,
true
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}
'
);
}
...
...
@@ -1110,10 +1117,10 @@ notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean):
```
ts
import
formHost
from
'
@ohos.application.formHost
'
;
let
formIds
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
let
formIds
:
string
[]
=
new
Array
(
'
12400633174999288
'
,
'
12400633174999289
'
);
formHost
.
notifyFormsEnableUpdate
(
formIds
,
true
).
then
(()
=>
{
console
.
log
(
'
formHost notifyFormsEnableUpdate success
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`formHost notifyFormsEnableUpdate, error:
${
JSON
.
stringify
(
error
)}
`
);
});
```
zh-cn/application-dev/reference/apis/js-apis-application-formProvider.md
浏览文件 @
b1f95d17
...
...
@@ -10,6 +10,7 @@ FormProvider模块提供了卡片提供方相关接口的能力,开发者在
```
ts
import
formProvider
from
'
@ohos.application.formProvider
'
;
import
Base
from
'
@ohos.base
'
```
## setFormNextRefreshTime
...
...
@@ -31,8 +32,8 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l
**示例:**
```
ts
let
formId
=
'
12400633174999288
'
;
formProvider
.
setFormNextRefreshTime
(
formId
,
5
,
(
error
,
data
)
=>
{
let
formId
:
string
=
'
12400633174999288
'
;
formProvider
.
setFormNextRefreshTime
(
formId
,
5
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}
'
);
}
...
...
@@ -63,11 +64,11 @@ setFormNextRefreshTime(formId: string, minute: number): Promise<void>
**示例:**
```
ts
let
formId
=
'
12400633174999288
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formProvider
.
setFormNextRefreshTime
(
formId
,
5
).
then
(()
=>
{
console
.
log
(
'
formProvider setFormNextRefreshTime success
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`formProvider setFormNextRefreshTime, error:
${
JSON
.
stringify
(
error
)}
`
);
});
```
...
...
@@ -93,10 +94,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
let
formId
=
'
12400633174999288
'
;
let
obj
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
updateForm
(
formId
,
obj
,
(
error
,
data
)
=>
{
class
createBindingDataType
{
temperature
:
string
time
:
string
};
let
createBindingDataParam
:
createBindingDataType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createBindingDataParam
);
formProvider
.
updateForm
(
formId
,
obj
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formProvider updateForm, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formProvider updateForm, error:
${
JSON
.
stringify
(
error
)}
`
);
}
});
```
...
...
@@ -127,12 +136,20 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
```
ts
import
formBindingData
from
'
@ohos.application.formBindingData
'
;
let
formId
=
'
12400633174999288
'
;
let
obj
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
let
formId
:
string
=
'
12400633174999288
'
;
class
createBindingDataType
{
temperature
:
string
time
:
string
};
let
createBindingDataParam
:
createBindingDataType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createBindingDataParam
);
formProvider
.
updateForm
(
formId
,
obj
).
then
(()
=>
{
console
.
log
(
'
formProvider updateForm success
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
formProvider updateForm, error: ${JSON.stringify(error)}
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`formProvider updateForm, error:
${
JSON
.
stringify
(
error
)}
`
);
});
```
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md
浏览文件 @
b1f95d17
...
...
@@ -13,6 +13,7 @@ FormExtensionContext模块提供FormExtensionAbility具有的接口和能力。
```
ts
import
common
from
'
@ohos.app.ability.common
'
;
import
Base
from
'
@ohos.base
'
;
```
## FormExtensionContext.startAbility
...
...
@@ -49,12 +50,13 @@ startAbility(want: Want, callback: AsyncCallback<void>): void
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
,
message
)
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// 当触发卡片message事件时,执行startAbility
console
.
log
(
'
FormExtensionAbility onFormEvent, formId: ${formId}, message:${message}
'
);
let
want
=
{
console
.
log
(
`FormExtensionAbility onFormEvent, formId:
${
formId
}
, message:
${
message
}
`
);
let
want
:
Want
=
{
deviceId
:
''
,
bundleName
:
'
com.example.formstartability
'
,
abilityName
:
'
EntryAbility
'
,
...
...
@@ -62,7 +64,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
'
message
'
:
message
}
};
this
.
context
.
startAbility
(
want
,
(
error
)
=>
{
this
.
context
.
startAbility
(
want
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
'
FormExtensionContext startAbility, error:${JSON.stringify(error)}
'
);
}
else
{
...
...
@@ -112,12 +114,13 @@ startAbility(want: Want): Promise<void>
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
,
message
)
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// 当触发卡片message事件时,执行startAbility
console
.
log
(
'
FormExtensionAbility onFormEvent, formId:${formId}, message:${message}
'
);
let
want
=
{
console
.
log
(
`FormExtensionAbility onFormEvent, formId:
${
formId
}
, message:
${
message
}
`
);
let
want
:
Want
=
{
deviceId
:
''
,
bundleName
:
'
com.example.formstartability
'
,
abilityName
:
'
EntryAbility
'
,
...
...
@@ -127,7 +130,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
};
this
.
context
.
startAbility
(
want
).
then
(()
=>
{
console
.
info
(
'
StartAbility Success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
StartAbility failed
'
);
});
}
...
...
@@ -176,41 +179,44 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
**示例:**
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
let
commRemote
=
null
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
,
message
)
{
// 当触发卡片message事件时,执行connectServiceExtensionAbility
console
.
log
(
`FormExtensionAbility onFormEvent, formId:
${
formId
}
, message:
${
message
}
`
);
let
want
=
{
deviceId
:
''
,
bundleName
:
'
com.example.formstartability
'
,
abilityName
:
'
EntryAbility
'
,
parameters
:
{
'
message
'
:
message
}
};
let
options
=
{
onConnect
(
elementName
,
remote
)
{
commRemote
=
remote
;
// remote 用于与ServiceExtensionAbility进行通信
console
.
log
(
'
----------- onConnect -----------
'
);
},
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
error
(
'
----------- onFailed -----------
'
)
}
};
let
connection
=
null
;
try
{
connection
=
this
.
context
.
connectServiceExtensionAbility
(
want
,
options
);
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
rpc
from
'
@ohos.rpc
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
commRemote
:
rpc
.
IRemoteObject
|
null
=
null
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// 当触发卡片message事件时,执行connectServiceExtensionAbility
console
.
log
(
`FormExtensionAbility onFormEvent, formId:
${
formId
}
, message:
${
message
}
`
);
let
want
:
Want
=
{
deviceId
:
''
,
bundleName
:
'
com.example.formstartability
'
,
abilityName
:
'
EntryAbility
'
,
parameters
:
{
'
message
'
:
message
}
};
let
options
:
common
.
ConnectOptions
=
{
onConnect
(
elementName
,
remote
)
{
commRemote
=
remote
;
// remote 用于与ServiceExtensionAbility进行通信
console
.
log
(
'
----------- onConnect -----------
'
);
},
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
error
(
'
----------- onFailed -----------
'
)
}
};
let
connection
:
number
|
null
=
null
;
try
{
connection
=
this
.
context
.
connectServiceExtensionAbility
(
want
,
options
);
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
}
};
```
}
};
```
## FormExtensionContext.disconnectServiceExtensionAbility<sup>10+</sup>
...
...
@@ -240,36 +246,38 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback<
**示例:**
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
rpc
from
'
@ohos.rpc
'
;
import
common
from
'
@ohos.app.ability.common
'
;
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
let
commRemote
=
null
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
,
message
)
{
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
let
connection
=
1
;
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
let
commRemote
:
rpc
.
IRemoteObject
|
null
=
null
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
let
connection
:
number
=
1
;
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
,
(
error
)
=>
{
commRemote
=
null
;
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
error
(
`disconnectServiceExtensionAbility failed, error.code:
${
error
.
code
}
, error.message:
${
error
.
message
}
`
);
return
;
}
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
});
}
catch
(
paramError
)
{
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
,
(
error
:
Base
.
BusinessError
)
=>
{
commRemote
=
null
;
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
}
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
error
(
`disconnectServiceExtensionAbility failed, error.code:
${
error
.
code
}
, error.message:
${
error
.
message
}
`
);
return
;
}
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
});
}
catch
(
paramError
)
{
commRemote
=
null
;
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
}
};
```
}
};
```
## FormExtensionContext.disconnectServiceExtensionAbility<sup>10+</sup>
...
...
@@ -304,34 +312,36 @@ disconnectServiceExtensionAbility(connection: number): Promise<void>;
**示例:**
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
let
commRemote
=
null
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
,
message
)
{
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
let
connection
=
1
;
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
)
.
then
((
data
)
=>
{
commRemote
=
null
;
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
})
.
catch
((
error
)
=>
{
commRemote
=
null
;
// 处理业务逻辑错误
console
.
error
(
`disconnectServiceExtensionAbility failed, error.code:
${
error
.
code
}
, error.message:
${
error
.
message
}
`
);
});
}
catch
(
paramError
)
{
commRemote
=
null
;
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
}
```
ts
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
rpc
from
'
@ohos.rpc
'
;
import
common
from
'
@ohos.app.ability.common
'
;
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
let
commRemote
:
rpc
.
IRemoteObject
|
null
=
null
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
let
connection
:
number
=
1
;
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
)
.
then
(()
=>
{
commRemote
=
null
;
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
})
.
catch
((
error
:
Base
.
BusinessError
)
=>
{
commRemote
=
null
;
// 处理业务逻辑错误
console
.
error
(
`disconnectServiceExtensionAbility failed, error.code:
${
error
.
code
}
, error.message:
${
error
.
message
}
`
);
});
}
catch
(
paramError
)
{
commRemote
=
null
;
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
}
};
```
}
};
```
zh-cn/application-dev/reference/apis/js-apis-inner-application-missionSnapshot.md
浏览文件 @
b1f95d17
...
...
@@ -28,7 +28,7 @@ import missionManager from '@ohos.app.ability.missionManager';
**示例:**
```
ts
import
ElementName
from
'
@ohos.bundle
'
;
import
ElementName
from
'
@ohos.bundle
.bundleManager
'
;
import
image
from
'
@ohos.multimedia.image
'
;
import
missionManager
from
'
@ohos.app.ability.missionManager
'
;
...
...
zh-cn/application-dev/reference/apis/js-apis-system-notification.md
浏览文件 @
b1f95d17
...
...
@@ -50,18 +50,24 @@ show(options?: ShowNotificationOptions): void
| options | ShowNotificationOptions | 否 | 通知标题。 |
**示例:**
```
javascript
export
default
{
show
()
{
notification
.
show
({
contentTitle
:
'
title info
'
,
contentText
:
'
text
'
,
clickAction
:
{
bundleName
:
'
com.example.testapp
'
,
abilityName
:
'
notificationDemo
'
,
uri
:
'
/path/to/notification
'
}
});
}
```
ts
class
NotificationClass
{
show
:
Function
}
let
notificationObj
:
NotificationClass
=
{
show
()
{
notification
.
show
({
contentTitle
:
'
title info
'
,
contentText
:
'
text
'
,
clickAction
:
{
bundleName
:
'
com.example.testapp
'
,
abilityName
:
'
notificationDemo
'
,
uri
:
'
/path/to/notification
'
}
});
}
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录