Android - Notifications

<blockquote > <p >A<span class="Apple-converted-space"></span><b >notification</b><span class="Apple-converted-space"></span>is a message you can display to the user outside of your application&#39;s normal UI. When you tell the system to issue a notification, it first appears as an icon in the notification area. To see the details of the notification, the user opens the notification drawer. Both the notification area and the notification drawer are system-controlled areas that the user can view at any time.</p> </blockquote> <p >Android<span class="Apple-converted-space"></span><b >Toast</b><span class="Apple-converted-space"></span>class provides a handy way to show users alerts but problem is that these alerts are not persistent which means alert flashes on the screen for a few seconds and then disappears.</p> <p><img alt="Android Notification Bar" src="http://www.tutorialspoint.com/android/images/notification_bar.jpg" /></p> <p >To see the details of the notification, you will have to select the icon which will display notification drawer having detail about the notification. While working with emulator with virtual device, you will have to click and drag down the status bar to expand it which will give you detail as follows. This will be just<span class="Apple-converted-space"></span><b >64 dp</b><span class="Apple-converted-space"></span>tall and called normal view.</p> <p><img alt="Android Notification Detail" src="http://www.tutorialspoint.com/android/images/notification_detail.jpg" /></p> <p >Above expanded form can have a<span class="Apple-converted-space"></span><b >Big View</b><span class="Apple-converted-space"></span>which will have additional detail about the notification. You can add upto six additional lines in the notification. The following screen shot shows such notification.</p> <h2 >Create and Send Notifications</h2> <p >You have simple way to create a notification. Follow the following steps in your application to create a notification &minus;</p> <h3 >Step 1 - Create Notification Builder</h3> <p >As a first step is to create a notification builder using<i >NotificationCompat.Builder.build()</i>. You will use Notification Builder to set various Notification properties like its small and large icons, title, priority etc.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="typ" >NotificationCompat</span><span class="pun" >.</span><span class="typ" >Builder</span><span class="pln" > mBuilder </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >NotificationCompat</span><span class="pun" >.</span><span class="typ" >Builder</span><span class="pun" >(</span><span class="kwd" >this</span><span class="pun" >)</span></pre> <h3 >Step 2 - Setting Notification Properties</h3> <p >Once you have<span class="Apple-converted-space"></span><b >Builder</b><span class="Apple-converted-space"></span>object, you can set its Notification properties using Builder object as per your requirement. But this is mandatory to set at least following &minus;</p> <ul class="list" > <li > <p >A small icon, set by<span class="Apple-converted-space"></span><b >setSmallIcon()</b></p> </li> <li > <p >A title, set by<span class="Apple-converted-space"></span><b >setContentTitle()</b></p> </li> <li > <p >Detail text, set by<span class="Apple-converted-space"></span><b >setContentText()</b></p> </li> </ul> <pre class="prettyprint notranslate prettyprinted" > <span class="pln" >mBuilder</span><span class="pun" >.</span><span class="pln" >setSmallIcon</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >drawable</span><span class="pun" >.</span><span class="pln" >notification_icon</span><span class="pun" >);</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >setContentTitle</span><span class="pun" >(</span><span class="str" >&quot;Notification Alert, Click Me!&quot;</span><span class="pun" >);</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >setContentText</span><span class="pun" >(</span><span class="str" >&quot;Hi, This is Android Notification Detail!&quot;</span><span class="pun" >);</span></pre> <p >You have plenty of optional properties which you can set for your notification. To learn more about them, see the reference documentation for NotificationCompat.Builder.</p> <h3 >Step 3 - Attach Actions</h3> <p >This is an optional part and required if you want to attach an action with the notification. An action allows users to go directly from the notification to an<b >Activity</b><span class="Apple-converted-space"></span>in your application, where they can look at one or more events or do further work.</p> <p >The action is defined by a<span class="Apple-converted-space"></span><b >PendingIntent</b><span class="Apple-converted-space"></span>containing an<span class="Apple-converted-space"></span><b >Intent</b><span class="Apple-converted-space"></span>that starts an Activity in your application. To associate the PendingIntent with a gesture, call the appropriate method of<span class="Apple-converted-space"></span><i >NotificationCompat.Builder</i>. For example, if you want to start Activity when the user clicks the notification text in the notification drawer, you add the PendingIntent by calling<span class="Apple-converted-space"></span><b >setContentIntent()</b>.</p> <p >A PendingIntent object helps you to perform an action on your applications behalf, often at a later time, without caring of whether or not your application is running.</p> <p >We take help of stack builder object which will contain an artificial back stack for the started Activity. This ensures that navigating backward from the Activity leads out of your application to the Home screen.</p> <pre class="result notranslate" > Intent resultIntent = new Intent(this, ResultActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ResultActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); </pre> <h3 >Step 4 - Issue the notification</h3> <p >Finally, you pass the Notification object to the system by calling NotificationManager.notify() to send your notification. Make sure you call<b >NotificationCompat.Builder.build()</b><span class="Apple-converted-space"></span>method on builder object before notifying it. This method combines all of the options that have been set and return a new<span class="Apple-converted-space"></span><b >Notification</b><span class="Apple-converted-space"></span>object.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="typ" >NotificationManager</span><span class="pln" > mNotificationManager </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >NotificationManager</span><span class="pun" >)</span><span class="pln" > getSystemService</span><span class="pun" >(</span><span class="typ" >Context</span><span class="pun" >.</span><span class="pln" >NOTIFICATION_SERVICE</span><span class="pun" >);</span><span class="pln" > </span><span class="com" >// notificationID allows you to update the notification later on.</span><span class="pln" > mNotificationManager</span><span class="pun" >.</span><span class="pln" >notify</span><span class="pun" >(</span><span class="pln" >notificationID</span><span class="pun" >,</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >build</span><span class="pun" >());</span></pre> <h2 >The NotificationCompat.Builder Class</h2> <p >The NotificationCompat.Builder class allows easier control over all the flags, as well as help constructing the typical notification layouts. Following are few important and most frequently used methods available as a part of NotificationCompat.Builder class.</p> <table class="table table-bordered" > <tbody > <tr > <th >Sr.No.</th> <th >Constants &amp; Description</th> </tr> <tr > <td >1</td> <td ><b >Notification build()</b> <p >Combine all of the options that have been set and return a new Notification object.</p> </td> </tr> <tr > <td >2</td> <td ><b >NotificationCompat.Builder setAutoCancel (boolean autoCancel)</b> <p >Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel.</p> </td> </tr> <tr > <td >3</td> <td ><b >NotificationCompat.Builder setContent (RemoteViews views)</b> <p >Supply a custom RemoteViews to use instead of the standard one.</p> </td> </tr> <tr > <td >4</td> <td ><b >NotificationCompat.Builder setContentInfo (CharSequence info)</b> <p >Set the large text at the right-hand side of the notification.</p> </td> </tr> <tr > <td >5</td> <td ><b >NotificationCompat.Builder setContentIntent (PendingIntent intent)</b> <p >Supply a PendingIntent to send when the notification is clicked.</p> </td> </tr> <tr > <td >6</td> <td ><b >NotificationCompat.Builder setContentText (CharSequence text)</b> <p >Set the text (second row) of the notification, in a standard notification.</p> </td> </tr> <tr > <td >7</td> <td ><b >NotificationCompat.Builder setContentTitle (CharSequence title)</b> <p >Set the text (first row) of the notification, in a standard notification.</p> </td> </tr> <tr > <td >8</td> <td ><b >NotificationCompat.Builder setDefaults (int defaults)</b> <p >Set the default notification options that will be used.</p> </td> </tr> <tr > <td >9</td> <td ><b >NotificationCompat.Builder setLargeIcon (Bitmap icon)</b> <p >Set the large icon that is shown in the ticker and notification.</p> </td> </tr> <tr > <td >10</td> <td ><b >NotificationCompat.Builder setNumber (int number)</b> <p >Set the large number at the right-hand side of the notification.</p> </td> </tr> <tr > <td >11</td> <td ><b >NotificationCompat.Builder setOngoing (boolean ongoing)</b> <p >Set whether this is an ongoing notification.</p> </td> </tr> <tr > <td >12</td> <td ><b >NotificationCompat.Builder setSmallIcon (int icon)</b> <p >Set the small icon to use in the notification layouts.</p> </td> </tr> <tr > <td >13</td> <td ><b >NotificationCompat.Builder setStyle (NotificationCompat.Style style)</b> <p >Add a rich notification style to be applied at build time.</p> </td> </tr> <tr > <td >14</td> <td ><b >NotificationCompat.Builder setTicker (CharSequence tickerText)</b> <p >Set the text that is displayed in the status bar when the notification first arrives.</p> </td> </tr> <tr > <td >15</td> <td ><b >NotificationCompat.Builder setVibrate (long[] pattern)</b> <p >Set the vibration pattern to use.</p> </td> </tr> <tr > <td >16</td> <td ><b >NotificationCompat.Builder setWhen (long when)</b> <p >Set the time that the event occurred. Notifications in the panel are sorted by this time.</p> </td> </tr> </tbody> </table> <h2 >Example</h2> <p >Following example shows the functionality of a Android notification using a<b >NotificationCompat.Builder</b><span class="Apple-converted-space"></span>Class which has been introduced in Android 4.1.</p> <table class="table table-bordered" > <tbody > <tr > <th class="fivepct" >Step</th> <th >Description</th> </tr> <tr > <td >1</td> <td >You will use Android studio IDE to create an Android application and name it as<span class="Apple-converted-space"></span><i >tutorialspoint<span class="Apple-converted-space"></span></i>under a package<span class="Apple-converted-space"></span><i >com.example.notificationdemo</i>. While creating this project, make sure you<span class="Apple-converted-space"></span><i >Target SDK</i><span class="Apple-converted-space"></span>and<span class="Apple-converted-space"></span><i >Compile With</i><span class="Apple-converted-space"></span>at the latest version of Android SDK to use higher levels of APIs.</td> </tr> <tr > <td >2</td> <td >Modify<span class="Apple-converted-space"></span><i >src/MainActivity.java</i><span class="Apple-converted-space"></span>file and add the code to notify(&quot;&quot;), if user click on the button,it will call android notification service.</td> </tr> <tr > <td >3</td> <td >Create a new Java file<span class="Apple-converted-space"></span><i >src/NotificationView.java</i>, which will be used to display new layout as a part of new activity which will be started when user will click any of the notifications</td> </tr> <tr > <td >4</td> <td >Modify layout XML file<span class="Apple-converted-space"></span><i >res/layout/activity_main.xml</i><span class="Apple-converted-space"></span>to add Notification button in relative layout.</td> </tr> <tr > <td >5</td> <td >Create a new layout XML file<span class="Apple-converted-space"></span><i >res/layout/notification.xml</i>. This will be used as layout file for new activity which will start when user will click any of the notifications.</td> </tr> <tr > <td >6</td> <td >No need to change default string constants. Android studio takes care of default string constants</td> </tr> <tr > <td >7</td> <td >Run the application to launch Android emulator and verify the result of the changes done in the application.</td> </tr> </tbody> </table> <p >Following is the content of the modified main activity file<b >src/com.example.notificationdemo/MainActivity.java</b>. This file can include each of the fundamental lifecycle methods.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="kwd" >package</span><span class="pln" > com</span><span class="pun" >.</span><span class="pln" >example</span><span class="pun" >.</span><span class="pln" >notificationdemo</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >Notification</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >NotificationManager</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >PendingIntent</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >content</span><span class="pun" >.</span><span class="typ" >Intent</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >support</span><span class="pun" >.</span><span class="pln" >v7</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >ActionBarActivity</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >os</span><span class="pun" >.</span><span class="typ" >Bundle</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >Menu</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >MenuItem</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >View</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >Button</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >class</span><span class="pln" > </span><span class="typ" >MainActivity</span><span class="pln" > </span><span class="kwd" >extends</span><span class="pln" > </span><span class="typ" >ActionBarActivity</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >Button</span><span class="pln" > b1</span><span class="pun" >;</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >protected</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onCreate</span><span class="pun" >(</span><span class="typ" >Bundle</span><span class="pln" > savedInstanceState</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >super</span><span class="pun" >.</span><span class="pln" >onCreate</span><span class="pun" >(</span><span class="pln" >savedInstanceState</span><span class="pun" >);</span><span class="pln" > setContentView</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >layout</span><span class="pun" >.</span><span class="pln" >activity_main</span><span class="pun" >);</span><span class="pln" > b1</span><span class="pun" >=(</span><span class="typ" >Button</span><span class="pun" >)</span><span class="pln" >findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >button</span><span class="pun" >);</span><span class="pln" > b1</span><span class="pun" >.</span><span class="pln" >setOnClickListener</span><span class="pun" >(</span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >View</span><span class="pun" >.</span><span class="typ" >OnClickListener</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onClick</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > v</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >Notify</span><span class="pun" >(</span><span class="str" >&quot;You&#39;ve received new message&quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >});</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >private</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > </span><span class="typ" >Notify</span><span class="pun" >(</span><span class="typ" >String</span><span class="pln" > notificationTitle</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >String</span><span class="pln" > notificationMessage</span><span class="pun" >){</span><span class="pln" > </span><span class="typ" >NotificationManager</span><span class="pln" > notificationManager </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >NotificationManager</span><span class="pun" >)</span><span class="pln" > getSystemService</span><span class="pun" >(</span><span class="pln" >NOTIFICATION_SERVICE</span><span class="pun" >);</span><span class="pln" > </span><span class="lit" >@SuppressWarnings</span><span class="pun" >(</span><span class="str" >&quot;deprecation&quot;</span><span class="pun" >)</span><span class="pln" > </span><span class="typ" >Notification</span><span class="pln" > notification </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >Notification</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >drawable</span><span class="pun" >.</span><span class="pln" >abc</span><span class="pun" >,</span><span class="str" >&quot;New Message&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >System</span><span class="pun" >.</span><span class="pln" >currentTimeMillis</span><span class="pun" >());</span><span class="pln" > </span><span class="typ" >Intent</span><span class="pln" > notificationIntent </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >Intent</span><span class="pun" >(</span><span class="kwd" >this</span><span class="pun" >,</span><span class="typ" >NotificationView</span><span class="pun" >.</span><span class="kwd" >class</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >PendingIntent</span><span class="pln" > pendingIntent </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >PendingIntent</span><span class="pun" >.</span><span class="pln" >getActivity</span><span class="pun" >(</span><span class="kwd" >this</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >,</span><span class="pln" >notificationIntent</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >);</span><span class="pln" > notification</span><span class="pun" >.</span><span class="pln" >setLatestEventInfo</span><span class="pun" >(</span><span class="typ" >MainActivity</span><span class="pun" >.</span><span class="kwd" >this</span><span class="pun" >,</span><span class="pln" > notificationTitle</span><span class="pun" >,</span><span class="pln" >notificationMessage</span><span class="pun" >,</span><span class="pln" > pendingIntent</span><span class="pun" >);</span><span class="pln" > notificationManager</span><span class="pun" >.</span><span class="pln" >notify</span><span class="pun" >(</span><span class="lit" >9999</span><span class="pun" >,</span><span class="pln" > notification</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >boolean</span><span class="pln" > onCreateOptionsMenu</span><span class="pun" >(</span><span class="typ" >Menu</span><span class="pln" > menu</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="com" >// Inflate the menu; this adds items to the action bar if it is present.</span><span class="pln" > getMenuInflater</span><span class="pun" >().</span><span class="pln" >inflate</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >menu</span><span class="pun" >.</span><span class="pln" >menu_main</span><span class="pun" >,</span><span class="pln" > menu</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >return</span><span class="pln" > </span><span class="kwd" >true</span><span class="pun" >;</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >boolean</span><span class="pln" > onOptionsItemSelected</span><span class="pun" >(</span><span class="typ" >MenuItem</span><span class="pln" > item</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="com" >// Handle action bar item clicks here. The action bar will</span><span class="pln" > </span><span class="com" >// automatically handle clicks on the Home/Up button, so long</span><span class="pln" > </span><span class="com" >// as you specify a parent activity in AndroidManifest.xml.</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > id </span><span class="pun" >=</span><span class="pln" > item</span><span class="pun" >.</span><span class="pln" >getItemId</span><span class="pun" >();</span><span class="pln" > </span><span class="com" >//noinspection SimplifiableIfStatement</span><span class="pln" > </span><span class="kwd" >if</span><span class="pln" > </span><span class="pun" >(</span><span class="pln" >id </span><span class="pun" >==</span><span class="pln" > R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >action_settings</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >return</span><span class="pln" > </span><span class="kwd" >true</span><span class="pun" >;</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >return</span><span class="pln" > </span><span class="kwd" >super</span><span class="pun" >.</span><span class="pln" >onOptionsItemSelected</span><span class="pun" >(</span><span class="pln" >item</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span></pre> <p >Following will be the content of<span class="Apple-converted-space"></span><b >res/layout/notification.xml</b><span class="Apple-converted-space"></span>file:</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;LinearLayout</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >android:orientation</span><span class="pun" >=</span><span class="atv" >&quot;vertical&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;fill_parent&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;fill_parent&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;fill_parent&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;400dp&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Hi, Your Detailed notification view goes here....&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/LinearLayout&gt;</span></pre> <p >Following is the content of the modified main activity file<b >src/com.example.notificationdemo/NotificationView.java</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="kwd" >package</span><span class="pln" > com</span><span class="pun" >.</span><span class="pln" >example</span><span class="pun" >.</span><span class="pln" >notificationdemo</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >os</span><span class="pun" >.</span><span class="typ" >Bundle</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >Activity</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >class</span><span class="pln" > </span><span class="typ" >NotificationView</span><span class="pln" > </span><span class="kwd" >extends</span><span class="pln" > </span><span class="typ" >Activity</span><span class="pun" >{</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onCreate</span><span class="pun" >(</span><span class="typ" >Bundle</span><span class="pln" > savedInstanceState</span><span class="pun" >){</span><span class="pln" > </span><span class="kwd" >super</span><span class="pun" >.</span><span class="pln" >onCreate</span><span class="pun" >(</span><span class="pln" >savedInstanceState</span><span class="pun" >);</span><span class="pln" > setContentView</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >layout</span><span class="pun" >.</span><span class="pln" >notification</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span></pre> <p >Following will be the content of<span class="Apple-converted-space"></span><b >res/layout/activity_main.xml</b><span class="Apple-converted-space"></span>file &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="tag" >&lt;RelativeLayout</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >xmlns:tools</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/tools&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:paddingBottom</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingLeft</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingRight</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingTop</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >tools:context</span><span class="pun" >=</span><span class="atv" >&quot;MainActivity&quot;</span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView1&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Notification Example&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentTop</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >&quot;30dp&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Tutorials point &quot;</span><span class="pln" > </span><span class="atn" >android:textColor</span><span class="pun" >=</span><span class="atv" >&quot;#ff87ff09&quot;</span><span class="pln" > </span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >&quot;30dp&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView1&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >&quot;48dp&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;ImageButton</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageButton&quot;</span><span class="pln" > </span><span class="atn" >android:src</span><span class="pun" >=</span><span class="atv" >&quot;@drawable/abc&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >&quot;42dp&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Notification&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button&quot;</span><span class="pln" > </span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >&quot;62dp&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageButton&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/RelativeLayout&gt;</span></pre> <p >Following will be the content of<span class="Apple-converted-space"></span><b >res/values/strings.xml</b><span class="Apple-converted-space"></span>to define two new constants &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;resources&gt;</span><span class="pln" > </span><span class="tag" >&lt;string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >&quot;action_settings&quot;</span><span class="tag" >&gt;</span><span class="pln" >Settings</span><span class="tag" >&lt;/string&gt;</span><span class="pln" > </span><span class="tag" >&lt;string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >&quot;app_name&quot;</span><span class="tag" >&gt;</span><span class="pln" >tutorialspoint </span><span class="tag" >&lt;/string&gt;</span><span class="pln" > </span><span class="tag" >&lt;/resources&gt;</span></pre> <p >Following is the default content of<span class="Apple-converted-space"></span><b >AndroidManifest.xml</b><span class="Apple-converted-space"></span>&minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;manifest</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >package</span><span class="pun" >=</span><span class="atv" >&quot;com.example.notificationdemo&quot;</span><span class="pln" > </span><span class="atn" >android:versionCode</span><span class="pun" >=</span><span class="atv" >&quot;1&quot;</span><span class="pln" > </span><span class="atn" >android:versionName</span><span class="pun" >=</span><span class="atv" >&quot;1.0&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;application</span><span class="pln" > </span><span class="atn" >android:allowBackup</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:icon</span><span class="pun" >=</span><span class="atv" >&quot;@drawable/ic_launcher&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;@string/app_name&quot;</span><span class="pln" > </span><span class="atn" >android:theme</span><span class="pun" >=</span><span class="atv" >&quot;@style/AppTheme&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;activity</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;com.example.notificationdemo.MainActivity&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;@string/app_name&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;action</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.intent.action.MAIN&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;category</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.intent.category.LAUNCHER&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;/activity&gt;</span><span class="pln" > </span><span class="tag" >&lt;activity</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;.NotificationView&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;Details of notification&quot;</span><span class="pln" > </span><span class="atn" >android:parentActivityName</span><span class="pun" >=</span><span class="atv" >&quot;.MainActivity&quot;</span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;meta-data</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.support.PARENT_ACTIVITY&quot;</span><span class="pln" > </span><span class="atn" >android:value</span><span class="pun" >=</span><span class="atv" >&quot;.MainActivity&quot;</span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/activity&gt;</span><span class="pln" > </span><span class="tag" >&lt;/application&gt;</span><span class="pln" > </span><span class="tag" >&lt;/manifest&gt;</span></pre> <p >Let&#39;s try to run your<span class="Apple-converted-space"></span><b >tutorialspoint</b><span class="Apple-converted-space"></span>application. I assume you had created your<b >AVD</b><span class="Apple-converted-space"></span>while doing environment set-up. To run the APP from Android Studio, open one of your project&#39;s activity files and click Run<span class="Apple-converted-space"></span><img alt="Eclipse Run Icon" class="inline" src="http://www.tutorialspoint.com/android/images/eclipse_run.jpg" /><span class="Apple-converted-space"></span>icon from the toolbar. Android Studio installs the app on your AVD and starts it and if everything is fine with your setup and application, it will display following Emulator window &minus;</p> <p><img alt="Android Notification Start" src="http://www.tutorialspoint.com/android/images/noti2.jpg" /></p> <p >Now click<span class="Apple-converted-space"></span><b >button</b>, you will see at the top a message &quot;New Message Alert!&quot; will display momentarily and after that you will have following screen having a small icon at the top left corner.</p> <p >Now lets expand the view, long click on the small icon, after a second it will display date information and this is the time when you should drag status bar down without releasing mouse. You will see status bar will expand and you will get following screen &minus;</p> <p><img alt="Android Notification Expanded" src="http://www.tutorialspoint.com/android/images/noti3.jpg" /></p> <h2 >Big View Notification</h2> <p >The following code snippet demonstrates how to alter the notification created in the previous snippet to use the Inbox big view style. I&#39;m going to update displayNotification() modification method to show this functionality &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="kwd" >protected</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > displayNotification</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >Log</span><span class="pun" >.</span><span class="pln" >i</span><span class="pun" >(</span><span class="str" >&quot;Start&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;notification&quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="com" >/* Invoking the default notification service */</span><span class="pln" > </span><span class="typ" >NotificationCompat</span><span class="pun" >.</span><span class="typ" >Builder</span><span class="pln" > mBuilder </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >NotificationCompat</span><span class="pun" >.</span><span class="typ" >Builder</span><span class="pun" >(</span><span class="kwd" >this</span><span class="pun" >);</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >setContentTitle</span><span class="pun" >(</span><span class="str" >&quot;New Message&quot;</span><span class="pun" >);</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >setContentText</span><span class="pun" >(</span><span class="str" >&quot;You&#39;ve received new message.&quot;</span><span class="pun" >);</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >setTicker</span><span class="pun" >(</span><span class="str" >&quot;New Message Alert!&quot;</span><span class="pun" >);</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >setSmallIcon</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >drawable</span><span class="pun" >.</span><span class="pln" >woman</span><span class="pun" >);</span><span class="pln" > </span><span class="com" >/* Increase notification number every time a new notification arrives */</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >setNumber</span><span class="pun" >(++</span><span class="pln" >numMessages</span><span class="pun" >);</span><span class="pln" > </span><span class="com" >/* Add Big View Specific Configuration */</span><span class="pln" > </span><span class="typ" >NotificationCompat</span><span class="pun" >.</span><span class="typ" >InboxStyle</span><span class="pln" > inboxStyle </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >NotificationCompat</span><span class="pun" >.</span><span class="typ" >InboxStyle</span><span class="pun" >();</span><span class="pln" > </span><span class="typ" >String</span><span class="pun" >[]</span><span class="pln" > events </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >String</span><span class="pun" >[</span><span class="lit" >6</span><span class="pun" >];</span><span class="pln" > events</span><span class="pun" >[</span><span class="lit" >0</span><span class="pun" >]</span><span class="pln" > </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >String</span><span class="pun" >(</span><span class="str" >&quot;This is first line....&quot;</span><span class="pun" >);</span><span class="pln" > events</span><span class="pun" >[</span><span class="lit" >1</span><span class="pun" >]</span><span class="pln" > </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >String</span><span class="pun" >(</span><span class="str" >&quot;This is second line...&quot;</span><span class="pun" >);</span><span class="pln" > events</span><span class="pun" >[</span><span class="lit" >2</span><span class="pun" >]</span><span class="pln" > </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >String</span><span class="pun" >(</span><span class="str" >&quot;This is third line...&quot;</span><span class="pun" >);</span><span class="pln" > events</span><span class="pun" >[</span><span class="lit" >3</span><span class="pun" >]</span><span class="pln" > </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >String</span><span class="pun" >(</span><span class="str" >&quot;This is 4th line...&quot;</span><span class="pun" >);</span><span class="pln" > events</span><span class="pun" >[</span><span class="lit" >4</span><span class="pun" >]</span><span class="pln" > </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >String</span><span class="pun" >(</span><span class="str" >&quot;This is 5th line...&quot;</span><span class="pun" >);</span><span class="pln" > events</span><span class="pun" >[</span><span class="lit" >5</span><span class="pun" >]</span><span class="pln" > </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >String</span><span class="pun" >(</span><span class="str" >&quot;This is 6th line...&quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="com" >// Sets a title for the Inbox style big view</span><span class="pln" > inboxStyle</span><span class="pun" >.</span><span class="pln" >setBigContentTitle</span><span class="pun" >(</span><span class="str" >&quot;Big Title Details:&quot;</span><span class="pun" >);</span><span class="pln" > </span><span class="com" >// Moves events into the big view</span><span class="pln" > </span><span class="kwd" >for</span><span class="pln" > </span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > i</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > i </span><span class="pun" >&lt;</span><span class="pln" > events</span><span class="pun" >.</span><span class="pln" >length</span><span class="pun" >;</span><span class="pln" > i</span><span class="pun" >++)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > inboxStyle</span><span class="pun" >.</span><span class="pln" >addLine</span><span class="pun" >(</span><span class="pln" >events</span><span class="pun" >[</span><span class="pln" >i</span><span class="pun" >]);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >setStyle</span><span class="pun" >(</span><span class="pln" >inboxStyle</span><span class="pun" >);</span><span class="pln" > </span><span class="com" >/* Creates an explicit intent for an Activity in your app */</span><span class="pln" > </span><span class="typ" >Intent</span><span class="pln" > resultIntent </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >Intent</span><span class="pun" >(</span><span class="kwd" >this</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >NotificationView</span><span class="pun" >.</span><span class="kwd" >class</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >TaskStackBuilder</span><span class="pln" > stackBuilder </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >TaskStackBuilder</span><span class="pun" >.</span><span class="pln" >create</span><span class="pun" >(</span><span class="kwd" >this</span><span class="pun" >);</span><span class="pln" > stackBuilder</span><span class="pun" >.</span><span class="pln" >addParentStack</span><span class="pun" >(</span><span class="typ" >NotificationView</span><span class="pun" >.</span><span class="kwd" >class</span><span class="pun" >);</span><span class="pln" > </span><span class="com" >/* Adds the Intent that starts the Activity to the top of the stack */</span><span class="pln" > stackBuilder</span><span class="pun" >.</span><span class="pln" >addNextIntent</span><span class="pun" >(</span><span class="pln" >resultIntent</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >PendingIntent</span><span class="pln" > resultPendingIntent </span><span class="pun" >=</span><span class="pln" >stackBuilder</span><span class="pun" >.</span><span class="pln" >getPendingIntent</span><span class="pun" >(</span><span class="lit" >0</span><span class="pun" >,</span><span class="typ" >PendingIntent</span><span class="pun" >.</span><span class="pln" >FLAG_UPDATE_CURRENT</span><span class="pun" >);</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >setContentIntent</span><span class="pun" >(</span><span class="pln" >resultPendingIntent</span><span class="pun" >);</span><span class="pln" > mNotificationManager </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >NotificationManager</span><span class="pun" >)</span><span class="pln" > getSystemService</span><span class="pun" >(</span><span class="typ" >Context</span><span class="pun" >.</span><span class="pln" >NOTIFICATION_SERVICE</span><span class="pun" >);</span><span class="pln" > </span><span class="com" >/* notificationID allows you to update the notification later on. */</span><span class="pln" > mNotificationManager</span><span class="pun" >.</span><span class="pln" >notify</span><span class="pun" >(</span><span class="pln" >notificationID</span><span class="pun" >,</span><span class="pln" > mBuilder</span><span class="pun" >.</span><span class="pln" >build</span><span class="pun" >());</span><span class="pln" > </span><span class="pun" >}</span></pre> <p >Now if you will try to run your application then you will find following result in expanded form of the view &minus;</p> <p><img alt="Android Notification Big View" src="http://i58.tinypic.com/55qtk3.jpg" /></p>
RangeTime:0.009327s
RangeMem:259.54 KB
返回顶部 留言