我知道这个问题被问了很多次,与推送通知状态栏图标有关,但我的问题有点不同。
我正在使用FCM推送通知,我的通知是正确的。我已经为预装棒棒糖和更多版本的棒棒糖设置了通知图标。我的通知图标在MOTO-G 5+等深色主题设备上显示正常,但当我在三星Galaxy Edge7.0等轻型主题设备上检查相同的通知时,我的通知图标会根据应用程序主题变成白色,但在另一个应用程序中,通知图标看起来正常。我看到了许多示例解决方案,但它们对我的问题没有帮助。
我使用了以下代码:
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ila_app_icon);
long when = System.currentTimeMillis();
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentText(message)
.setContentIntent(pendingIntent)
// .setColor(getNotificationColor())
.setSmallIcon(getNotificationIcon(notificationBuilder))
.setWhen(when)
.setSound(defaultSoundUri)
.setLargeIcon(bitmap);
Random random = new Random();
int uniqueIntegerNumber = random.nextInt(9999 - 1000) + 1000;
notificationManager.notify(uniqueIntegerNumber, notificationBuilder.build());
获取通知图标方法:-
private int getNotificationIcon(NotificationCompat.Builder notificationBuilder) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int color = 0x008000;
notificationBuilder.setColor(color);
return R.drawable.notification_white;
}
return R.drawable.ila_app_icon;
}
我也尝试过setColor属性,但同样不起作用。
1)轻主题(此处为白旗图标)
这是屏幕截图:
2)黑暗主题:-
发布于 2018-07-04 18:23:59
在所有的搜索和其他事情之后,我找到了我的解决方案,除了通知图标之外,一切都运行得很好,图标保持了一点不同颜色的像素。
我们可以从下面的链接创建通知图标,它使我们的图标对通知透明
https://stackoverflow.com/questions/51169822
复制相似问题