Android 将显示白色方形,而不是我的通知图标
我正在尝试构建我自己的通知,当我在FCM接收器中收到来自服务器的有效负载时,我将通知图标设置为PNG格式的应用程序图标,但是,我的通知显示为白色方块,我不知道为什么。。 这是我的密码:Android 将显示白色方形,而不是我的通知图标,android,push-notification,icons,notification-icons,Android,Push Notification,Icons,Notification Icons,我正在尝试构建我自己的通知,当我在FCM接收器中收到来自服务器的有效负载时,我将通知图标设置为PNG格式的应用程序图标,但是,我的通知显示为白色方块,我不知道为什么。。 这是我的密码: NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.icon) .setContentTitl
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.icon)
.setContentTitle("Your chat is going to expire tomorrow!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, main_activity.class);
resultIntent.putExtra("launchedFromNotification",true);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your app to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(main_activity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mNotificationId is a unique integer your app uses to identify the
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
这通常发生在使用非alpha图标时 当您在通知上使用图标时,android会在图标的所有非alpha(不透明)部分上绘制。这意味着,如果您使用一个正方形图像作为通知图标,它将显示为白色正方形 要解决此问题,只需使用类似图标的形状。请检查以下内容以供参考:
那么我该怎么做才能将其转换为alpha图标呢?将您的图标添加到问题中你好,艾哈迈德·凯里,我一直在绝望地想您能找到解决方案,我发现了这篇文章,如果您完全按照上面所说的做,图标的问题就消失了。我的目标是Android O设备和带有SDK(27)的应用程序,现在一切正常。