We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
quickApp ReferencesQuick AppAPIUI InteractionNotification

Notification

NOTE

To standardize notification messages for a better experience, Push Kit will be fully updated from May 19, 2023 for quick apps.

During the update, the push capability will be unavailable. That is, push messages and notification messages cannot reach users in quick apps. We apologize for any inconvenience caused to you.

The service update is expected to be completed in the fourth quarter of 2023. We will notify you by email after that. If you have any questions, please send an email to developer@huawei.com. Thank you for your support.

API Declaration

Add the following configuration to the features attribute in the manifest.json file:

Collapse
Word wrap
Dark theme
Copy code
  1. {"name": "system.notification"}

Module Import

Add the following configuration to the script element on the page where the API will be called:

Collapse
Word wrap
Dark theme
Copy code
  1. import notification from '@system.notification'

Or

Collapse
Word wrap
Dark theme
Copy code
  1. var notification = require("@system.notification")

Application Scope

Expand

Item

Description

Applicable devices

Mobile phones and tablets

Applicable regions

Chinese mainland

Definition

Expand

API

Description

notification.show(OBJECT)

Displays notifications.

notification.postDelayedShow(OBJECT)

Displays notifications with a delay.

notification.cancelDelayedShow(OBJECT)

Cancels displaying notifications with a delay.

notification.show(OBJECT)

Description

Displays notifications.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

contentTitle

string

No

Title. If the notification permission is not assigned, no notification will be displayed. If the notification permission is assigned, this parameter cannot be left empty. Otherwise, notifications cannot be displayed.

contentText

string

No

Content. If the notification permission is not assigned, no notification will be displayed. If the notification permission is assigned, this parameter cannot be left empty. Otherwise, notifications cannot be displayed.

clickAction

object

No

Action triggered when a notification is tapped.

clickAction parameters

Expand

Parameter

Type

Mandatory

Description

uri

string

Yes

URI of the page that is displayed after a notification is tapped. The following formats are supported:

  1. In-app page path that starts with a slash (/), for example, /about.
  2. In-app page path that does not start with a slash (/), for example, About.
  3. /: A page whose path is / is displayed; otherwise, the home page is displayed.

You can use "?param1=value1" to add a parameter. Then you can use this parameter on a page using this.param1.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. notification.show({
  2. contentTitle:'title',
  3. clickAction: {
  4. uri:'/index.html?index=1'
  5. }
  6. })

notification.postDelayedShow(OBJECT) (1070+, Huawei Extended API, Not Formulated by the Vendor Alliance)

Description

Displays notifications with a delay.

NOTE

A notification will be displayed only if the process of the quick app sending this notification is running. Otherwise, notifications cannot be displayed.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

message

object

Yes

Notification details.

buildInfo

object

Yes

Delay settings.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

message parameters

Expand

Parameter

Type

Mandatory

Description

contentTitle

string

No

Title. If the notification permission is not assigned, no notification will be displayed. If the notification permission is assigned, this parameter cannot be left empty. Otherwise, notifications cannot be displayed.

contentText

string

No

Content. If the notification permission is not assigned, no notification will be displayed. If the notification permission is assigned, this parameter cannot be left empty. Otherwise, notifications cannot be displayed.

clickAction

object

No

Action triggered when a notification is tapped.

buildInfo parameters

Expand

Parameter

Type

Mandatory

Description

latencyTime

long

Yes

Delay time, in seconds.

isPersisted

boolean

Yes

Indicates whether notifications are persisted even when a mobile phone is restarted. This setting takes effect after you enable auto launch on Huawei Quick App Center.

Parameters returned by success

Expand

Parameter

Type

Description

jobId

int

ID of a delayed message.

This ID can be used to cancel a notification delay task.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. notification.postDelayedShow({
  2. message:{
  3. contentTitle: 'title',
  4. clickAction: {
  5. uri: '/index.html?index=1'
  6. }
  7. },
  8. buildInfo:{
  9. latencyTime: 1*60, // 1 minute
  10. isPersisted:false
  11. },
  12. success:function(params){
  13. console.info("success, id is "+ params.jobId)
  14. }
  15. })

notification.cancelDelayedShow(OBJECT) (1070+, Huawei Extended API, Not Formulated by the Vendor Alliance)

Description

Cancels displaying notifications with a delay.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

jobId

int

Yes

ID of a delayed message.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. notification.cancelDelayedShow({
  2. jobId:12,
  3. success:function(params){
  4. console.info("success")
  5. }
  6. })

Demo

Collapse
Word wrap
Dark theme
Copy code
  1. <template>
  2. <div class="container">
  3. <div class="item-container">
  4. <div class="item-content">
  5. <div class="item-content-detail">
  6. <text class="txt">Title:</text>
  7. <input class="input" placeholder="Please input title" onchange="titleFn" />
  8. </div>
  9. <div class="item-content-detail">
  10. <text class="txt">Content:</text>
  11. <input class="input" placeholder="Please input content" onchange="contentFn" />
  12. </div>
  13. </div>
  14. <input type="button" class="btn" value="Send a notification" onclick="show" />
  15. <input type="button" class="btn" value="Post delayed show" onclick="delayedshow" />
  16. <input type="button" class="btn" value="Cancel delayed show" onclick="canceldelayedshow" />
  17. </div>
  18. </div>
  19. </template>
  20. <style>
  21. .container{
  22. flex: 1;
  23. flex-direction: column;
  24. }
  25. .item-container {
  26. margin-top: 50px;
  27. margin-right: 60px;
  28. margin-left: 60px;
  29. flex-direction: column;
  30. }
  31. .item-content {
  32. flex-direction: column;
  33. background-color: #ffffff;
  34. padding-left: 30px;
  35. padding-right: 30px;
  36. padding-top: 15px;
  37. padding-bottom: 15px;
  38. margin-bottom: 100px;
  39. }
  40. .item-content-detail {
  41. align-items: center;
  42. }
  43. .input {
  44. flex: 1;
  45. font-size: 30px;
  46. padding-left: 20px;
  47. }
  48. .txt {
  49. width: 150px;
  50. padding-top: 15px;
  51. padding-bottom: 15px;
  52. text-align: right;
  53. }
  54. .btn {
  55. height: 80px;
  56. text-align: center;
  57. border-radius: 5px;
  58. margin-right: 60px;
  59. margin-left: 60px;
  60. margin-bottom: 50px;
  61. color: #ffffff;
  62. font-size: 30px;
  63. background-color: #0faeff;
  64. }
  65. </style>
  66. <script>
  67. import prompt from '@system.prompt'
  68. import notification from '@system.notification'
  69. export default {
  70. data: {
  71. componentData: {},
  72. inputTitle: 'title',
  73. inputContent: 'content',
  74. testjobId:''
  75. },
  76. onInit: function () {
  77. this.$page.setTitleBar({ text: 'notification' })
  78. },
  79. show: function () {
  80. var that = this
  81. prompt.showToast({
  82. message: 'Message whose title is "' + that.inputTitle + ' "has been sent. Check it in the notification bar.',
  83. })
  84. notification.show({
  85. contentTitle: that.inputTitle,
  86. contentText: that.inputContent,
  87. clickAction: {
  88. uri: '/Hello'
  89. }
  90. })
  91. },
  92. titleFn: function (e) {
  93. this.inputTitle = e.text
  94. },
  95. contentFn: function (e) {
  96. this.inputContent = e.text
  97. },
  98. delayedshow: function () {
  99. var that = this;
  100. notification.postDelayedShow({
  101. message:{
  102. contentTitle: 'title',
  103. contentText:'post delayed show',
  104. clickAction: {
  105. uri: '/Hello'
  106. }
  107. },
  108. buildInfo:{
  109. latencyTime: 1*60, // 1 minute
  110. isPersisted:false
  111. },
  112. success:function(params){
  113. console.info("success, id is "+ params.jobId);
  114. that.testjobId = params.jobId;
  115. },
  116. fail:function(code) {
  117. console.log("failed, code is "+ code);
  118. },
  119. complete:function(data) {
  120. console.log("delayed show complete!");
  121. }
  122. })
  123. },
  124. canceldelayedshow:function () {
  125. notification.cancelDelayedShow({
  126. jobId:this.testjobId,
  127. success:function(params){
  128. console.info("success cancel delayed show")
  129. },
  130. fail:function(code) {
  131. console.log("cancel delayed show failed! code is "+code)
  132. },
  133. complete:function() {
  134. console.log("cancel delayed show complete!")
  135. }
  136. })
  137. }
  138. }
  139. </script>

The following figure shows the final effect.

Version Change History

Expand

Version

Date

Description

1070

2020-05-19

  • Added the postDelayedShow method to set delayed notifications.
  • Added the cancelDelayedShow method to cancel notification delay.