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

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

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

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

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

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

// 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);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值