Home | History | Annotate | Download | only in notifications
      1 page.title=Adding Pages to a Notification
      2 
      3 @jd:body
      4 
      5 <div id="tb-wrapper">
      6 <div id="tb">
      7 
      8 <h2>This lesson teaches you to</h2>
      9 <ol>
     10   <li>Add Pages to a Notification</li>
     11 </ol>
     12 </div>
     13 </div>
     14 
     15 <p>When you'd like to provide more information without requiring users
     16 to open your app on their handheld device, you can
     17 add one or more pages to the notification on the wearable. The additional pages
     18 appear immediately to the right of the main notification card.
     19 </p>
     20 
     21 <img src="{@docRoot}wear/images/09_pages.png" height="200" style="margin:0 0 20px 0" />
     22 <img src="{@docRoot}wear/images/08_pages.png" height="200" style="margin:0 0 20px 40px" />
     23 
     24 <p>To create a notification with multiple pages:</p>
     25 <ol>
     26     <li>Create the main notification (the first page) with
     27     {@link android.support.v4.app.NotificationCompat.Builder},
     28     in the way you'd like the notification to appear on a handset.</li>
     29     <li>Create the additional pages for the wearable with
     30     {@link android.support.v4.app.NotificationCompat.Builder}.</li>
     31     <li>Apply the pages to the main notification with the
     32     {@link android.support.v4.app.NotificationCompat.WearableExtender#addPage addPage()}
     33     method or add multiple pages in a {@link java.util.Collection} with the
     34     {@link android.support.v4.app.NotificationCompat.WearableExtender#addPage addPages()} method.
     35     </li>
     36 </ol>
     37 
     38 <p>For example, here's some code that adds a second page to a notification:</p>
     39 
     40 <pre>
     41 // Create builder for the main notification
     42 NotificationCompat.Builder notificationBuilder =
     43         new NotificationCompat.Builder(this)
     44         .setSmallIcon(R.drawable.new_message)
     45         .setContentTitle("Page 1")
     46         .setContentText("Short message")
     47         .setContentIntent(viewPendingIntent);
     48 
     49 // Create a big text style for the second page
     50 BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
     51 secondPageStyle.setBigContentTitle("Page 2")
     52                .bigText("A lot of text...");
     53 
     54 // Create second page notification
     55 Notification secondPageNotification =
     56         new NotificationCompat.Builder(this)
     57         .setStyle(secondPageStyle)
     58         .build();
     59 
     60 // Add second page with wearable extender and extend the main notification
     61 Notification twoPageNotification =
     62         new WearableExtender()
     63                 .addPage(secondPageNotification)
     64                 .extend(notificationBuilder)
     65                 .build();
     66 
     67 // Issue the notification
     68 notificationManager =
     69         NotificationManagerCompat.from(this);
     70 notificationManager.notify(notificationId, twoPageNotification);
     71 </pre>