Android Notification Big Picture Style and Big Text Style

22,436

Solution 1

You should be able to do it this way:

Notification notif = new Notification.Builder(context)
     .setContentTitle("Title")
     .setContentText("content")
     .setSmallIcon(R.drawable.ic_small)
     .setLargeIcon(bitmap)
     .setStyle(new Notification.BigPictureStyle()
         .bigPicture(bigBitmap)
         .setBigContentTitle("big title"))
     .build();

Source

Solution 2

View More... text in your norification is subtext. So while using bigpicturestyle notification you need to set

bigPicStyle.setSummaryText(mContent);

or

mBuilder.setSubText(mSubText);

Setting both at same time doesn't work.

Solution 3

Example of how to create a BigPictureStyle Notification:

 int NOTIFICATION_ID = 1;
    String ns = Context.NOTIFICATION_SERVICE;

    //Get the bitmap to show in notification bar
    Bitmap bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    Bitmap big_bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);


    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle()
            .bigPicture(big_bitmap_image)
            .setSummaryText(getResources().getString(R.string.content));

    NotificationCompat.Builder nb = new NotificationCompat.Builder(this);

            nb.setContentTitle("Notification title"))
            .setContentText("Notification Content")
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(bitmap_image)
            .setTicker("Notification ticker!")
            //API Level min 16 is required
            .setStyle(style)
            .build();


    Intent notificationIntent = new Intent(this, MainActivity2.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    TaskStackBuilder TSB = TaskStackBuilder.create(this);
    TSB.addParentStack(MainActivity.class);

    TSB.addNextIntent(notificationIntent);
    PendingIntent resultPendingIntent = TSB.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    nb.setContentIntent(resultPendingIntent);
    nb.setAutoCancel(true);
    NotificationManager mNotificationManager =
            (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(NOTIFICATION_ID, nb.build());

this is the complete code:

https://github.com/Jorgesys/Android-Notifications

Share:
22,436
Mitsus
Author by

Mitsus

Updated on April 19, 2020

Comments

  • Mitsus
    Mitsus about 4 years

    I've build a push notification using Big Picture Style as show here. Is it possible to mix Big picture Style and Big Text Style as shown in the attached photo? How do I do it?

    enter image description here