【发布时间】:2017-09-15 12:16:55
【问题描述】:
我知道要支持 Lollipop Material 设计指南,我们必须让通知图标透明。
这是我的 FCM onMessageReceived() 函数,用于显示通知。
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
NotificationCompat.Builder mBuilder;
mBuilder = new NotificationCompat.Builder(this)
.setContentTitle(remoteMessage.getNotification().getBody()) // title for notification
.setContentText(remoteMessage.getNotification().getTitle()) // message for notification
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
.setSmallIcon(getNotificationIcon())
.setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, CheckInListPage.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.logo_a_transparent : R.drawable.logo_notifc;
}
但这里我的问题是,当应用程序在前台运行并且可见时,它将采用我的 logo_a_transparent 并获得所需的结果(屏幕截图 - 通知栏中的第一个图标)。
但是当我们暂停应用程序并且 FCM 推送到来时,它需要我的应用程序图标 (android:icon="@drawable/ic_launcher") 作为通知图标变成白色(屏幕截图 - 通知栏中的第二个图标)。
将应用图标替换为透明可以,但不是正确的解决方案。
【问题讨论】:
-
因为你在使用GetNotification() insteam 每次都使用getData() 方法调用onmessageReceived,而且你可以使用相同的图标
-
我已经这样做了...但是当我们暂停应用程序并且 FCM 推送到来时,通知图标变为白色(屏幕截图 - 通知栏中的第二个图标)。应用前台时,没有问题。
-
它只是给一个颜色,但问题还没有解决。问题是当应用程序暂停时,fcm 推送通知使用应用程序图标而不是我的透明图标。这可以通过将应用程序图标设置为透明来解决,但这对应用程序图标来说并不舒适。
标签: java android push-notification