我已经设置了我的通知图标,但它显示了mipmap ic_launcher icon.Plese帮助我在收到通知时显示图标。
private void addNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity())
.setSmallIcon(R.mipmap.logo)
.setLargeIcon(BitmapFactory.decodeResource(getActivity().getResources(),
R.mipmap.logo))
.setContentTitle("Delivery Boy")
.setWhen(System.currentTimeMillis())
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentText("You have Pending Orders");
Intent notificationIntent = new Intent(getContext(), MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(getContext(), 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
// Add as notification
NotificationManager manager = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
答案 0 :(得分:0)
原因:对于5.0 Lollipop“通知图标必须完全为白色”。
如果您想支持Lollipop材质图标,请为Lollipop及以上版本制作透明图标。请参阅以下https://design.google.com/icons/
以下Lollipop操作系统版本的Notification Builder实现将是:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setSmallIcon(R.drawable.icon_transperent);
} else {
builder.setSmallIcon(R.drawable.icon);
}
如果要为所有操作系统版本设置彩色单个图标,则
解决方案:对于彩色图标,请使用
defaultConfig {
applicationId "com.your.app.pkj"
minSdkVersion xx
targetSdkVersion 20 // < 21 (target sdk version in manifest file will be less than 21).
versionCode x
versionName "x.x"
}
Icon not displaying in notification: white square shown instead