【问题标题】:Notification background image never shown on clock通知背景图像从未显示在时钟上
【发布时间】:2014-03-21 09:32:41
【问题描述】:

我没有得到它设法显示我根据 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);
}

有什么想法吗?

这是我的输出:

【问题讨论】:

  • 只是一个猜测:还有其他点可以设置图像。也许磨损是从其他人那里得到的。 Builder.setLargeIconBigPictureStyle.bigLargeIconBigPictureStyle.bigPicture 也许是其中之一。

标签: android wear-os


【解决方案1】:

正确的方法是使用WearableExtender,就像在这个简短的例子中一样:

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

原始答案 /替代

我找到了一个解决方案,我需要像这样使用 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));

【讨论】:

  • 您是否可以为可穿戴通知设置 BigPictureStyle 为手机通知设置“标准”样式?
  • @Reustonium 正如我在问题部分中指出的那样, setMinPriority 调用强制通知仅显示在时钟上。可能还有另一个电话可以避免这种情况,因此您可以简单地创建两个不同的通知。但是,也许也可以实现支持两者的自定义样式,但我还不知道。
猜你喜欢
  • 2015-07-02
  • 1970-01-01
  • 2014-02-07
  • 2020-12-16
  • 2021-03-30
  • 2015-10-30
  • 2016-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多