Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification background image never shown on clock

I don't get it manages to show the background I did that based on the ElizaChat example but I don't get the background it is always black.

Here is my code:

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);
}

Any Idea?

This is my output:

clock

like image 251
rekire Avatar asked Nov 01 '22 03:11

rekire


1 Answers

The right way is to use the WearableExtender like in this short example:

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

Original Answer / alternative

I found a solution I need to use the BigPictureStyle like this:

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));
like image 164
rekire Avatar answered Nov 12 '22 08:11

rekire