【发布时间】:2018-07-04 19:29:32
【问题描述】:
我正在尝试在我的 FCM 接收器中收到来自服务器的有效负载后立即构建自己的通知,我将通知图标设置为 PNG 格式的应用程序图标,但是,我的通知显示为而是白色方块,我不知道为什么.. 这是我的代码:
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());
【问题讨论】:
-
你好 Ahmed Khairy,我一直很绝望,就像你在寻找解决方案一样,我发现这篇文章如果你完全按照它所说的那样做,图标的问题就消失了。我的目标是 Android O 设备和带有 SDK (27) 的应用程序,现在一切正常。 stackoverflow.com/a/48562435/3438335
标签: android push-notification icons notification-icons