blob: 8d3fb1d56894c98cff04dde69a1b3d465cfebbb0 [file] [log] [blame]
Trevor Johnsa6b46362013-10-30 16:38:01 -07001<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright 2013 The Android Open Source Project
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17
18<sample>
19 <name>BasicNotifications</name>
Renato Manginiebeca0e2014-11-11 17:55:39 -080020 <group>Notification</group>
Trevor Johnsa6b46362013-10-30 16:38:01 -070021 <package>com.example.android.basicnotifications</package>
22 <!-- change minSdk if needed-->
23 <minSdk>8</minSdk>
24
25 <strings>
26 <intro>
27 <![CDATA[
28 This sample demonstrates how to display events in the system\'s notification bar. The
29 NotificationCompat API is used for compatibility with older devices, running Android
30 2.2 (Froyo) or newer.
31 ]]>
32 </intro>
33 </strings>
34
35 <template src="base"/>
Takeshi Hagikurab6fe0152014-11-23 11:26:41 +090036
37 <metadata>
38 <status>PUBLISHED</status>
39 <categories>Notification</categories>
40 <technologies>Android</technologies>
41 <languages>Java</languages>
42 <solutions>Mobile</solutions>
43 <level>BEGINNER</level>
44 <icon>Application/src/main/big_icon.png</icon>
45 <screenshots>
46 <img>screenshots/main.png</img>
47 </screenshots>
48 <api_refs>
49 <android>android.app.NotificationManager</android>
50 <android>android.support.v4.app.NotificationCompat</android>
51 </api_refs>
52
53 <description>
54A basic app showing how to display events in the system's notification bar using
55the NotificationCompat API.
56NotificationCompat API is used for compatibility with older devices, running Android
571.6 (Donut) (API level 4) or newer.
58 </description>
59
60 <intro>
61<![CDATA[
62The [Notification API][1] allows the app developers to display a message outside
63of your application's normal UI.
64
65The class [Notification][2] was added in the Android 3.0 (API level 11), but this
66sample refers to the [NotificationCompat][3] class (part of the [support library][4]),
67 which offers the same functionality for Android 1.6 (API level 4) or newer.
68
69A Notificaiton can be created using Notification.Builder object.
70At bare minimum, a Builder object must include the following:
71- A small icon, set by [setSmallIcon()][5]
72- A title, set by [setContentTitle()][6]
73- Detail text, set by [setContentText()][7]
74
75in the code snippet, it looks like following.
76```java
77NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
78builder.setSmallIcon(R.drawable.ic_stat_notification);
79builder.setContentTitle("BasicNotifications Sample");
80builder.setContentText("Time to learn about notifications!");
81```
82
83To issue the notification, call notify() method in the [NotificationManager][8].
84The code snippet will immediately display the notification icon in the
85notification bar.
86
87```java
88NotificationManager notificationManager = (NotificationManager) getSystemService(
89 NOTIFICATION_SERVICE);
90notificationManager.notify(NOTIFICATION_ID, builder.build());
91```
92
93[1]: http://developer.android.com/guide/topics/ui/notifiers/notifications.html
94[2]: http://developer.android.com/reference/android/app/Notification.html
95[3]: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.html
96[4]: http://developer.android.com/tools/support-library/index.html
97[5]: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setSmallIcon(int)
98[6]: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentTitle(java.lang.CharSequence)
99[7]: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentText(java.lang.CharSequence)
100[8]: http://developer.android.com/reference/android/app/NotificationManager.html
101]]>
102 </intro>
103 </metadata>
Trevor Johnsa6b46362013-10-30 16:38:01 -0700104</sample>