I've read the ~10 similar questions to this on SO, and some other google search, and documentation pages, and I still can't figure out what the issue is.
Basically, if the app is closed (or backgrounded), the push notification icon shows up as a white square.
If the app is running, it shows up with the icon I want.
My icon is transparent, and just white. Its a simple icon that comes from Google itself.
Here's what I have, and where the issue may be. Our app has multiple modules. I'll focus on 3 of them:
- App
- AppCode
- PushNotification
I'm building the local notification on the PushNotification
module:
override fun onMessageReceived(from: String?, data: Bundle?) {
super.onMessageReceived(from, data)
Log.d("PNReceiver", "onMessageReceived")
val notification = data?.get("notification") as Bundle?
val notificationTitle = notification?.get("title") as String
val notificationBody = notification?.get("body") as String
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val channelId = getString(R.string.notification_channel_id)
if(manager.getNotificationChannel(channelId) == null) {
val channel = NotificationChannel(channelId,
getString(R.string.notification_channel_name),
NotificationManager.IMPORTANCE_DEFAULT)
channel.description =
getString(R.string.notification_channel_description)
manager.createNotificationChannel(channel)
}
createLocalNotification(manager, channelId, notificationTitle, notificationBody)
}
}
private fun createLocalNotification(notificationManager: NotificationManager,
channelId: String,
title: String,
body: String) {
val largeIcon = BitmapFactory.decodeResource(resources, R.drawable.ic_cake_variant)
val builder = NotificationCompat.Builder(this, channelId)
.setContentTitle(title)
.setContentText(body)
.setStyle(NotificationCompat.BigTextStyle().bigText(body))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setSmallIcon(R.drawable.ic_cake_variant)
.setLargeIcon(largeIcon)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND or Notification.DEFAULT_LIGHTS or Notification.DEFAULT_VIBRATE)
notificationManager.notify(0, builder.build())
}
Also, I'm trying to push the exact same icon, on the manifest of the PushNotification
module:
<application>
... some gcm stuff...
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/notification_channel_id" />
<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_cake_variant" />
</application>
The other 2 modules (App
and AppCode
) don't have anything related to the push notification code.
FWIW, our data flow/dependency graph of modules is App
-> AppCode
-> PushNotification
Also, we're still using GCM and not FCM, on version com.google.android.gms:play-services-gcm:11.8.0
Tried version 15.0.1
, with no success either.
Am I missing something super obvious? Thank you for your help.
UPDATE
Here's what the body of the received message looks like:
Bundle[{
google.sent_time = 1526919xxxxxx,
google.message_id = 0: 1526919xxxxxxx % xxx c5e8a46xxxxxx,
notification = Bundle[{
body = test message 1,
title = test title 1
}],
message = test message 1,
collapse_key = com.mycompany
}]
Also, here are some of the other answers I've reviewed: