Home | History | Annotate | Download | only in BasicNotifications
      1 <?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>
     20     <group>Notification</group>
     21     <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"/>
     36 
     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>
     54 A basic app showing how to display events in the system's notification bar using
     55 the NotificationCompat API.
     56 NotificationCompat API is used for compatibility with older devices, running Android
     57 1.6 (Donut) (API level 4) or newer.
     58         </description>
     59 
     60         <intro>
     61 <![CDATA[
     62 The [Notification API][1] allows the app developers to display a message outside
     63 of your application's normal UI.
     64 
     65 The class [Notification][2] was added in the Android 3.0 (API level 11), but this
     66 sample 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 
     69 A Notificaiton can be created using Notification.Builder object.
     70 At 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 
     75 in the code snippet, it looks like following.
     76 ```java
     77 NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
     78 builder.setSmallIcon(R.drawable.ic_stat_notification);
     79 builder.setContentTitle("BasicNotifications Sample");
     80 builder.setContentText("Time to learn about notifications!");
     81 ```
     82 
     83 To issue the notification, call notify() method in the [NotificationManager][8].
     84 The code snippet will immediately display the notification icon in the
     85 notification bar.
     86 
     87 ```java
     88 NotificationManager notificationManager = (NotificationManager) getSystemService(
     89         NOTIFICATION_SERVICE);
     90 notificationManager.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>
    104 </sample>
    105