Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Big Picture is Cropping while setting to Notification

I want to show a Big Picture Style Image in my notification bar Android. But I am getting a problem -> When I set the image in notification bar using the below code:

PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(title)
            .setContentText(message)
            .setOngoing(false)
            .setAutoCancel(true)
            .setStyle(new NotificationCompat.BigPictureStyle()
            .bigPicture(bitmap))
            .setPriority(Notification.PRIORITY_HIGH)
            //.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setContentIntent(resultPendingIntent);
            // mId allows you to update the notification later on.
            mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
            NotificationManager mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(0 , mBuilder.build());

It is always cropped from left and right corners. I dont want to use remote views for the same. Can anyone tell me the size and the resolutions of the image that can be placed in the notification bar which should not be cropped.

Thanks

like image 807
Gaurav Arora Avatar asked Nov 30 '22 10:11

Gaurav Arora


2 Answers

The reason its being cropped because its not in 2:1 ratio image that you are providing for big picture should be in 2:1 ratio else it will get cropped or image is small it will get stretch.

Check this out https://documentation.onesignal.com/docs/android-customizations#section-big-picture

like image 122
Rohit Raich Avatar answered Dec 15 '22 23:12

Rohit Raich


Why not use a layout instead of a bitmap? Here is a tutorial on how to do it, http://codeversed.com/expandable-notifications-android/ and in the layout you can adjust the imageview properties to centre and scale the image and also use android's screen size buckets to fetch the images optimized for specific screen sizes. Let me know if that helps.

EDIT: Did any of the solutions help you achieve, what you desired? If so accept one of the answers, as it may help someone else. Thank you

like image 41
EmptyCup Avatar answered Dec 15 '22 23:12

EmptyCup