通知图像从不在Android中显示



如果假设我使用安卓工作室的图像资产工具上传png图像来创建通知图标,并选择类型作为通知,它会生成通知图标规范所需尺寸的所有必需图标吗?如果是,那么在通知栏中显示此图标应该不会有任何问题,不是吗?嗯,在我的情况下并没有,但不管怎样,它都会显示默认的应用程序图标。下面是我的代码。任何人猜测它为什么会失败,也许这只是一个化妆品问题。

NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("VEDRISE",
"Vedic Notifications",
NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("Will display daily Panchang notificatons");
mNotificationManager.createNotificationChannel(channel);
}
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
//      URL url = new //URL("https://66.media.tumblr.com/ec76b7d7e0529af6e3a437edb6c6c255/tumblr_phiur//jqePq1xp0noco1_75sq.png");
//     Bitmap image = //BitmapFactory.decodeStream(url.openConnection().getInputStream());
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, "VEDRISE")
.setSmallIcon(R.drawable.sunrise) // notification icon
//      .setLargeIcon(image)
.setContentTitle(title) // title for notification
.setContentText(content)// message for notification
.setSound(alarmSound) // set alarm sound for notification
.setAutoCancel(true); // clear notification after click
Intent intent = new Intent(context, this.getClass());
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pi);
int id = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
Log.d("VedicHoroo", String.format("id: %d", id));
mNotificationManager.notify( id, mBuilder.build());

只是为了给您一些范围,这个要求是本地通知,它将由AlarmReceiver触发。接收器由警报触发而没有问题,但通知不显示由setSmallIcon设置的图像,而只显示应用程序图标

Notification notification  = new Notification.Builder(this)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.drawable.ic_notification)
.setContentIntent(pIntent)
.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setAutoCancel(true)
.build();

即使ic_notification是透明的和白色的。它也必须在Manifest元数据中定义,如下所示:

<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />

在应用程序块的manifest.xml文件中添加此行

最新更新