【发布时间】:2015-10-13 09:39:23
【问题描述】:
我有两种方式的通知实现: 1.大图标+小图标(标题+留言) 2. LargeIcon + SmallIcon +Big Pictuire.(Title+ Message+ Message2(PicURL) )
第一个工作正常,大图标和小图标显示在右下角。
对于第二个实现。我可以看到大图+小图标。 但是只有当我在通知中展开大图片时,我才会看到大图标。 如何在通知上显示带有大图片的 LargeIcon + Small Icon?
代码如下:
private void sendNotification(String title, String msg, String msg1) {
Log.i("msg1", "" + msg1);
NotificationCompat.BigPictureStyle s = new NotificationCompat.BigPictureStyle();
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Context context = getApplicationContext();
Intent myIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
context,
0,
myIntent,
PendingIntent.FLAG_ONE_SHOT); //Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this)
.setContentTitle(title)
.setAutoCancel(true)
.setContentText(msg)
.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE);
if(msg1 == null)
{
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.app_icon);
mBuilder.setLargeIcon(largeIcon);
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
}
else
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
//http://stackoverflow.com/questions/22119374/how-to-show-compact-notification-if-it-is-available-on-the-user-device
try {
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.app_icon);
s.bigLargeIcon(largeIcon);
s.bigPicture(Picasso.with(context).load(msg1).get());
} catch (IOException e) {
e.printStackTrace();
}
mBuilder.setStyle(s);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder
.setSmallIcon(R.mipmap.ic_notification)
.setColor(ContextCompat.getColor(context, R.color.bgColor));
} else {
mBuilder.setSmallIcon(R.drawable.ic_notification);
}
mBuilder.setContentIntent(pendingIntent);
int notifID =(int)System.currentTimeMillis();
mNotificationManager.notify(notifID, mBuilder.build());
}
【问题讨论】: