Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
95de9f6d
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
未验证
提交
95de9f6d
编写于
3月 16, 2023
作者:
O
openharmony_ci
提交者:
Gitee
3月 16, 2023
浏览文件
操作
浏览文件
下载
差异文件
!14983 【轻量级 PR】:update zh-cn/application-dev/notification/text-notification.md.
Merge pull request !14983 from zyjhandsome/N/A
上级
2c001ab0
8f5012e3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
38 deletion
+37
-38
zh-cn/application-dev/notification/text-notification.md
zh-cn/application-dev/notification/text-notification.md
+37
-38
未找到文件。
zh-cn/application-dev/notification/text-notification.md
浏览文件 @
95de9f6d
...
@@ -16,13 +16,13 @@
...
@@ -16,13 +16,13 @@
目前系统仅通知栏订阅了通知,将通知显示在通知栏里。基础类型通知呈现效果示意图如下所示。
目前系统仅通知栏订阅了通知,将通知显示在通知栏里。基础类型通知呈现效果示意图如下所示。
**图1**
基础类型通知呈现效果示意图
**图1**
基础类型通知呈现效果示意图
!
[
zh-cn_image_0000001466462305
](
figures/zh-cn_image_0000001466462305.png
)

## 接口说明
## 接口说明
通知发布接口如下表所示,不同发布类型通知由
[
NotificationRequest
](
../reference/apis/js-apis-notification.md#notificationrequest
)
的字段携带不同的信息。
通知发布接口如下表所示,不同发布类型通知由
[
NotificationRequest
](
../reference/apis/js-apis-notification
Manager
.md#notificationrequest
)
的字段携带不同的信息。
|
**接口名**
|
**描述**
|
|
**接口名**
|
**描述**
|
| -------- | -------- |
| -------- | -------- |
...
@@ -38,17 +38,17 @@
...
@@ -38,17 +38,17 @@
2.
导入模块。
2.
导入模块。
```
ts
```
ts
import
N
otificationManager
from
'
@ohos.notificationManager
'
;
import
n
otificationManager
from
'
@ohos.notificationManager
'
;
```
```
3.
构造NotificationRequest对象,并发布通知。
3.
构造NotificationRequest对象,并发布通知。
-
普通文本类型通知由标题、文本内容和附加信息三个字段组成,其中标题和文本内容是必填字段,大小均需要小于200字节。
-
普通文本类型通知由标题、文本内容和附加信息三个字段组成,其中标题和文本内容是必填字段,大小均需要小于200字节。
```
ts
```
ts
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
id
:
1
,
id
:
1
,
content
:
{
content
:
{
contentType
:
N
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_BASIC_TEXT
,
// 普通文本类型通知
contentType
:
n
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_BASIC_TEXT
,
// 普通文本类型通知
normal
:
{
normal
:
{
title
:
'
test_title
'
,
title
:
'
test_title
'
,
text
:
'
test_text
'
,
text
:
'
test_text
'
,
...
@@ -57,25 +57,24 @@
...
@@ -57,25 +57,24 @@
}
}
}
}
N
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
n
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`[ANS]
failed to publish, error[
${
err
}
]
`
);
console
.
error
(
`[ANS]
publish failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`[ANS] publish success`
);
console
.
info
(
`[ANS] publish success
.
`
);
});
});
```
```
运行效果如下图所示。
运行效果如下图所示。


-
长文本类型通知继承了普通文本类型的字段,同时新增了长文本内容、内容概要和通知展开时的标题,其中长文本内容不超过1024字节,其他字段小于200字节。通知默认显示与普通文本相同,展开后,标题显示为展开后标题内容,内容为长文本内容。
-
长文本类型通知继承了普通文本类型的字段,同时新增了长文本内容、内容概要和通知展开时的标题,其中长文本内容不超过1024字节,其他字段小于200字节。通知默认显示与普通文本相同,展开后,标题显示为展开后标题内容,内容为长文本内容。
```
ts
```
ts
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
id
:
1
,
id
:
1
,
content
:
{
content
:
{
contentType
:
N
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_LONG_TEXT
,
// 长文本类型通知
contentType
:
n
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_LONG_TEXT
,
// 长文本类型通知
longText
:
{
longText
:
{
title
:
'
test_title
'
,
title
:
'
test_title
'
,
text
:
'
test_text
'
,
text
:
'
test_text
'
,
...
@@ -88,24 +87,24 @@
...
@@ -88,24 +87,24 @@
}
}
// 发布通知
// 发布通知
N
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
n
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`[ANS]
failed to publish, error[
${
err
}
]
`
);
console
.
error
(
`[ANS]
publish failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`[ANS] publish success`
);
console
.
info
(
`[ANS] publish success
.
`
);
});
});
```
```
运行效果如下图所示。
运行效果如下图所示。
!
[
zh-cn_image_0000001416745530
](
figures/zh-cn_image_0000001416745530.png
)
!
[
zh-cn_image_0000001416745530
](
figures/zh-cn_image_0000001416745530.png
)
-
多行文本类型通知继承了普通文本类型的字段,同时新增了多行文本内容、内容概要和通知展开时的标题,其字段均小于200字节。通知默认显示与普通文本相同,展开后,标题显示为展开后标题内容,多行文本内容多行显示。
-
多行文本类型通知继承了普通文本类型的字段,同时新增了多行文本内容、内容概要和通知展开时的标题,其字段均小于200字节。通知默认显示与普通文本相同,展开后,标题显示为展开后标题内容,多行文本内容多行显示。
```
ts
```
ts
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
id
:
1
,
id
:
1
,
content
:
{
content
:
{
contentType
:
N
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_MULTILINE
,
// 多行文本类型通知
contentType
:
n
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_MULTILINE
,
// 多行文本类型通知
multiLine
:
{
multiLine
:
{
title
:
'
test_title
'
,
title
:
'
test_title
'
,
text
:
'
test_text
'
,
text
:
'
test_text
'
,
...
@@ -117,45 +116,45 @@
...
@@ -117,45 +116,45 @@
}
}
// 发布通知
// 发布通知
N
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
n
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`[ANS]
failed to publish, error[
${
err
}
]
`
);
console
.
error
(
`[ANS]
publish failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`[ANS] publish success`
);
console
.
info
(
`[ANS] publish success`
);
});
});
```
```
运行效果如下图所示。
运行效果如下图所示。
!
[
zh-cn_image_0000001417062446
](
figures/zh-cn_image_0000001417062446.png
)
!
[
zh-cn_image_0000001417062446
](
figures/zh-cn_image_0000001417062446.png
)
-
图片类型通知继承了普通文本类型的字段,同时新增了图片内容、内容概要和通知展开时的标题,图片内容为PixelMap型对象,其大小不能超过2M。
-
图片类型通知继承了普通文本类型的字段,同时新增了图片内容、内容概要和通知展开时的标题,图片内容为PixelMap
类
型对象,其大小不能超过2M。
```
ts
```
ts
let
notificationPicture
:
PixelMap
=
undefined
;
// 需要获取图片PixelMap信息
let
imagePixelMap
:
PixelMap
=
undefined
;
// 需要获取图片PixelMap信息
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
id
:
1
,
id
:
1
,
content
:
{
content
:
{
contentType
:
N
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_PICTURE
,
contentType
:
n
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_PICTURE
,
picture
:
{
picture
:
{
title
:
'
test_title
'
,
title
:
'
test_title
'
,
text
:
'
test_text
'
,
text
:
'
test_text
'
,
additionalText
:
'
test_additionalText
'
,
additionalText
:
'
test_additionalText
'
,
briefText
:
'
test_briefText
'
,
briefText
:
'
test_briefText
'
,
expandedTitle
:
'
test_expandedTitle
'
,
expandedTitle
:
'
test_expandedTitle
'
,
picture
:
notificationPicture
picture
:
imagePixelMap
}
}
}
}
}
}
// 发布通知
// 发布通知
N
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
n
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`[ANS]
failed to publish, error[
${
err
}
]
`
);
console
.
error
(
`[ANS]
publish failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`[ANS] publish success
`
);
console
.
info
(
`[ANS] publish success
.
`
);
});
});
```
```
运行效果如下图所示。
运行效果如下图所示。
!
[
zh-cn_image_0000001466582045
](
figures/zh-cn_image_0000001466582045.png
)
!
[
zh-cn_image_0000001466582045
](
figures/zh-cn_image_0000001466582045.png
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录