1 <h1 id=
"richNotifications">Rich Notifications
</h1>
3 <p>The
<a href=
"https://developer.chrome.com/apps/notifications">rich notifications API
</a>
4 lets you create notifications using templates and
5 show these notifications to users in the user's system tray:
8 <p><img src=
"{{static}}/images/notifications.png"
9 alt=
"Notifications in system user tray">
12 <h2 id=
"look">How they look
</h2>
15 Rich notifications come in four different flavors:
16 basic, image, list, and progress.
17 All notifications include a title, message, small icon displayed
18 to the left of the notification message, and a contextMessage field,
19 which is displayed as a
3rd text field in a lighter color font.
27 <img src=
"{{static}}/images/basic_notification.png"
28 alt=
"Basic notification">
32 List notifications display any number of list items:
36 <img src=
"{{static}}/images/list_notification.png"
37 alt=
"List notification">
41 Image notifications include an image preview:
45 <img src=
"{{static}}/images/image_notification.png"
46 alt=
"Image notification">
49 Progress notifications show a progress bar:
51 <img src=
"{{static}}/images/progress_notification.png"
52 alt=
"Progress notification">
55 <h2 id=
"behave">How they behave
</h2>
58 Notifications show up in a user's system tray,
59 and stay in the system tray until the user dismisses them.
61 the bell icon is lit when there's new notifications;
63 the system tray keeps a count of all new notifications.
64 Once a users sees the notifications in the system tray,
65 the count is reset to zero;
69 Notifications can be assigned a priority between -
2 to
2.
70 Priorities <
0 are only shown in the center;
71 priorities
> 0 are shown for increasing duration and
72 more high priority notifications can be displayed in the system tray.
76 In addition to displaying information,
77 all notification types can include up to two action items.
78 When users click on an action item,
79 your app can respond with the appropriate action.
81 when the user clicks on
"Reply",
82 the email app opens and the user can complete the reply:
85 <p><img src=
"{{static}}/images/action_notification.png"
86 alt=
"Action in notification">
89 <h2 id=
"develop">How to develop them
</h2>
93 call the $(ref:notifications.create) method,
94 passing in the notification details
95 via the
<code>options
</code> parameter:
99 chrome.notifications.create(id, options, creationCallback);
103 The $(ref:notifications.NotificationOptions) must include a
104 $(ref:notifications.TemplateType),
105 which defines available notification details
106 and how those details are displayed.
110 <b>Consider integrating with GCM!
</b><br>
111 <a href=
"inform_users">Keep your users informed
</a> all the time,
112 even when your app isn't opened.
113 The
<a href=
"https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/gcm-notifications">gcm-notifications sample
</a>
114 shows a simple integration between GCM and Rich Notifications API.
117 <h3 id=
"basic">Create basic notification
</h3>
121 (
<code>basic
</code>,
<code>image
</code>,
<code>list
</code> and
<code>progress
</code>)
122 must include a notification
<code>title
</code> and
<code>message
</code>,
123 as well as an
<code>iconUrl
</code>, which is a link to a small icon that
124 is displayed to the left of the notification message.
128 Here's an example of a
<code>basic
</code> template:
134 title:
"Primary Title",
135 message:
"Primary message to display",
136 iconUrl:
"url_to_small_icon"
140 <h3 id=
"image">Create image notification
</h3>
143 The
<code>image
</code>
144 template type also includes an
<code>imageUrl
</code>, which is a link to
145 an image that is previewed within the notification:
151 title:
"Primary Title",
152 message:
"Primary message to display",
153 iconUrl:
"url_to_small_icon",
154 imageUrl:
"url_to_preview_image"
159 In Chrome Apps, due to a strict
<a href=
"contentSecurityPolicy">Content Security Policy
</a>
160 these URLs must point to a local resource or use a
161 <a href=
"app_external">blob or data URL
</a>.
162 Use a
3:
2 ratio for your image; otherwise a black border frames the image.
165 <h3 id=
"list">Create list notification
</h3>
168 The
<code>list
</code> template displays
<code>items
</code>
175 title:
"Primary Title",
176 message:
"Primary message to display",
177 iconUrl:
"url_to_small_icon",
178 items: [{ title:
"Item1", message:
"This is item 1."},
179 { title:
"Item2", message:
"This is item 2."},
180 { title:
"Item3", message:
"This is item 3."}]
184 <h3 id=
"list">Create progress notification
</h3>
187 The
<code>progress
</code> template displays a progress bar where current
188 progress ranges from
0 to
100:
194 title:
"Primary Title",
195 message:
"Primary message to display",
196 iconUrl:
"url_to_small_icon",
202 <h2 id=
"events">Listening for and responding to events
</h2>
205 All notifications can include event listeners and event handlers
206 that respond to user actions (see
<a href=
"events">chrome.events
</a>).
208 you can write an event handler to respond to an
209 $(ref:notifications.onButtonClicked) event.
212 <p>Event listener:
</p>
215 chrome.notifications.onButtonClicked.addListener(replyBtnClick);
218 <p>Event handler:
</p>
221 function replyBtnClick {
222 //Write function to respond to user action.
226 <p>Consider including event listeners and handlers within the
227 <a href=
"app_lifecycle#create_event_page">event page
</a>,
228 so that notifications can pop-up even when the app or extension isn't running.