为通知添加更多页面(Adding Pages to a Notification)

来源:互联网 发布:软件服务协会 编辑:程序博客网 时间:2024/05/19 19:32

为通知添加更多页面(Adding Pages to a Notification)

当你想提供更多的信息,而这些信息不需要用户打开手机去查看,此时你可以添加一个或者多个页面在wear的通知中.更多的页面内容会立即呈现在主通知卡片的右侧.
这里写图片描述
这里写图片描述

通过以下步骤创建拥有多个页面的通知:

  1. 首先使用NotificationCompat.Builder创建一个主通知,这里创建的通知和展示在手机上的通知创建方式一样.
  2. 使用NotificationCompat.Builder为通知创建更多的页面.
  3. 使用方法addPage()或者addPages()讲创建的页面添加到主通知中.

举个栗子,下面是添加第二个页面到通知中的代码.

// Create builder for the main notificationNotificationCompat.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 pageBigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();secondPageStyle.setBigContentTitle("Page 2")               .bigText("A lot of text...");// Create second page notificationNotification secondPageNotification =        new NotificationCompat.Builder(this)        .setStyle(secondPageStyle)        .build();// Extend the notification builder with the second pageNotification notification = notificationBuilder        .extend(new NotificationCompat.WearableExtender()                .addPage(secondPageNotification))        .build();// Issue the notificationnotificationManager =        NotificationManagerCompat.from(this);notificationManager.notify(notificationId, notification);
0 0