与Android Wear上的列表通知一样

时间:2014-07-24 15:47:40

标签: android android-notifications wear-os

Hangout使用特定的Notification,在Android Wear上向右滑动时会显示消息列表。它显示ListView中的所有邮件。

他们是否使用特定Notification Style(例如InboxStyleBigTextStyle)?可能是Wear App吗? (我不这么认为,他们无法通过刷卡进行访问)

1 个答案:

答案 0 :(得分:2)

他们正在为其通知添加Pages,允许您为Android Wear设备添加其他内容。

链接中的示例代码:

// 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();

// Add second page with wearable extender and extend the main notification
Notification twoPageNotification =
    new WearableExtender()
            .addPage(secondPageNotification)
            .extend(notificationBuilder)
            .build();

// Issue the notification
notificationManager =
    NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, twoPageNotification);