【发布时间】:2017-06-21 19:54:14
【问题描述】:
我刚刚在我的 Android 应用程序中实现了 FCM 推送通知,我得到了一个奇怪的行为,因为它似乎只在应用程序打开时加载剪影图标,但是当它关闭或最小化时,我得到一个白色圆圈。我认为它向我展示了 ic_launcher 图标而不是我的 ic_stat_white 图标。我在 photoshop 中制作了我的基本图标,并使用 Android Asset Studio 来获取所有尺寸(https://romannurik.github.io/AndroidAssetStudio/icons-notification.html),我尝试了所有我能找到或想到的解决方案,在推送通知消息中添加了一个额外的值(“icon”: “ic_stat_white”),使缓存无效,以及我在 Stack Overflow 中可以找到的所有内容,但没有结果。
在我的 Firebase 消息服务类中,我有以下代码来创建通知:
NotificationCompat.Builder mBuilder =
(NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(getNotificationIcon())
.setContentTitle("App name")
.setAutoCancel(true)
.setContentText(message);
mBuilder.setContentIntent(resultPendingIntent);
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
和getNotificationIcon方法:
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.ic_stat_white : R.mipmap.ic_launcher;
}
我觉得应用程序无法从应用程序外部访问图标或类似的东西,虽然我已经添加了
import com.appname.R;
它似乎根本没有被使用。
有人知道这里可能出现什么问题吗?
干杯!
【问题讨论】:
-
请在此处查看我对同一问题的回答:stackoverflow.com/questions/37616065/…
标签: android firebase firebase-cloud-messaging android-notifications