【发布时间】:2014-08-18 10:48:48
【问题描述】:
我已经使用大图片样式构建了一个推送通知,如 show here。 如附图所示,是否可以混合使用大图片样式和大文本样式?我该怎么做?
【问题讨论】:
-
请检查这个解决方案,它会帮助你stackoverflow.com/a/44757879/3946958
标签: android notifications push-notification
我已经使用大图片样式构建了一个推送通知,如 show here。 如附图所示,是否可以混合使用大图片样式和大文本样式?我该怎么做?
【问题讨论】:
标签: android notifications push-notification
你应该可以这样做:
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();
【讨论】:
查看更多... 您的通知中的文字是潜台词。 所以在使用 bigpicturestyle 通知时你需要设置
bigPicStyle.setSummaryText(mContent);
或
mBuilder.setSubText(mSubText);
不能同时设置。
【讨论】:
如何创建BigPictureStyle 通知的示例:
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());
这是完整的代码:
【讨论】: