通知背景图像从未在时钟上显示

时间:2014-03-21 09:32:41

标签: android wear-os

我没有设法根据ElizaChat示例显示我所做的背景,但我没有得到它总是黑色的背景。

这是我的代码:

public static void createNotification(Context context) {
    int notificationId = 1;

    NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
    bigStyle.bigText("I am a big style message");

    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(context)
            //.setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("hallo")
            .setContentText("I am a message")
            .setLargeIcon(BitmapFactory.decodeResource(
                context.getResources(), R.drawable.clock_bg))
            //.setStyle(bigStyle)
            ;

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

    Notification notification =
        new WearableNotifications.Builder(notificationBuilder)
            .setHintHideIcon(true)
            .setMinPriority() // show only on clock
            .build();

    // Build the notification and issues it with notification manager.
    notificationManager.notify(notificationId, notification);
}

任何想法?

这是我的输出:

clock

1 个答案:

答案 0 :(得分:2)

正确的方法是在这个简短的例子中使用WearableExtender

NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
Bitmap bg = BitmapFactory.decodeResource(context.getResources(), background);
extender.setBackground(bg);
notificationBuilder.extend(extender);

原始答案 / alternative

我找到了一个我需要使用BigPictureStyle的解决方案:

Bitmap background = BitmapFactory.decodeResource(context.getResources(),
                                                 R.drawable.clock_bg);

NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(context)
                .setContentTitle("hallo")
                .setContentText("I am a message")
                .setLargeIcon(background)
                .setStyle(new NotificationCompat.BigPictureStyle()
                                                .bigPicture(background));