Search code examples
androidnotificationsalarmmanager

Android - Big picture notification not showing depending on image size


I'm trying to implement big picture notifications on Android and I'm finding there seem to be some undocumented image size restrictions which make my notifications not work depending on the image size I use.

For example, if I put a 1024x512 image in drawable-xxxhdpi (which should get scaled appropriately for lower density devices), then the notification never shows. If I put a 512x256 image, it shows perfectly every time. Both of these images are much smaller than the 256 dp height that big picture notifications are supposed to support.

I've stepped through the code and everything works as expected. Notifications are created and scheduled properly (I get no errors or exceptions) in both cases, they just never show up. The notification is created when the app is sent to the background and for testing purposes I'm setting them to trigger in a few seconds.

I've tried with a lot of image sizes, and aspect ratios, and kind of narrowed it down but the numbers seem to be different for different devices.

Is there anywhere I can get some information about these limits? (See edit). Is there maybe something I should be doing to make sure my notifications get triggered despite the image size?

Here's the code I'm using. Sorry if it looks a bit weird, this is a large codebase and I copied and pasted code from several functions.

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setContentTitle(title);
notificationBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
notificationBuilder.setWhen(0);
notificationBuilder.setContentText(content);

Bitmap notificationLargeIconBitmap = BitmapFactory.decodeResource(Activity.getResources(), R.drawable.ic_lollipop_noti);
notificationBuilder.setLargeIcon(notificationLargeIconBitmap);
notificationBuilder.setSmallIcon(R.drawable.ic_lollipop_statbar);
notificationBuilder.setColor(0xffe20b00);

Bitmap bigPicture = BitmapFactory.decodeResource(activity.getResources(), R.drawable.notif_image);
NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
style.setBigContentTitle(p_title);
style.setSummaryText(p_content);
style.bigPicture(bigPicture);
notificationBuilder.setStyle(style);

Intent resultIntent = new Intent(context, Launcher.class);
resultIntent.setAction(Intent.ACTION_MAIN);
resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
notificationBuilder.setContentIntent(pendingIntent);

Notification notification = notificationBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;

Intent intent = new Intent(context, LocalNotificationEmitter.class);
intent.setAction(NOTIFICATION);
intent.putExtra(LocalNotificationEmitter.NOTIFICATION_TAG, id);
intent.setData(Uri.parse(id));
intent.putExtra(LocalNotificationEmitter.NOTIFICATION, p_notification);
PendingIntent mAlarmIntent = PendingIntent.getBroadcast(contex, 0, intent,
                Intent.FLAG_GRANT_READ_URI_PERMISSION);

Long delay = Long.valueOf(delay) * 1000;
long futureInMillis = System.currentTimeMillis() + delay;
mAlarmManager.set(AlarmManager.RTC, futureInMillis, mAlarmIntent);

EDIT: I made a simple application just to test big picture notifications and that one is working with any image sizes. So clearly something is wrong with the code we're using on the main app. Anyone see anything wrong in the code I posted? I'll keep looking...


Solution

  • In case this can help anyone, I've found out that moving the notification creation to the LocalNotificationEmitter class' onReceive method instead of bundling it into the intent makes it work every time.