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