為通知添加更多頁面(Adding Pages to a Notification)
當(dāng)你想提供更多的信息,而這些信息不需要用戶打開手機(jī)去查看,此時(shí)你可以添加一個或者多個頁面在wear的通知中.更多的頁面內(nèi)容會立即呈現(xiàn)在主通知卡片的右側(cè).
這里寫圖片描述
這里寫圖片描述
// Create builder for the main notification
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.new_message)
.setContentTitle("Page 1")
.setContentText("Short message")
.setContentIntent(viewPendingIntent);
// Create a big text style for the second page
BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
secondPageStyle.setBigContentTitle("Page 2")
.bigText("A lot of text...");
// Create second page notification
Notification secondPageNotification =
new NotificationCompat.Builder(this)
.setStyle(secondPageStyle)
.build();
// Extend the notification builder with the second page
Notification notification = notificationBuilder
.extend(new NotificationCompat.WearableExtender()
.addPage(secondPageNotification))
.build();
// Issue the notification
notificationManager =
NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, notification);