2

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:

Question 1

Question 2

Question 3

TooManyEduardos
  • 3,516
  • 5
  • 28
  • 61
  • The code looks fine. I assume you're using a `data`-only message payload? Do point out the links that you already checked so that the suggested solutions would be narrowed down. Also, please proceed with using FCM, even though it doesn't solve this specific issue, it might prevent others from occurring. – AL. May 19 '18 at 03:08
  • 1
    I'll review this on Monday, but what do you mean with "Do point out the links that you already checked so that the suggested solutions would be narrowed down". Also, FCM is not really an option yet since it requires backend changes that just simply won't happen anytime soon (different team with different priorities) – TooManyEduardos May 19 '18 at 04:50
  • Hey there. Sorry if it was confusing, what I meant was if you could post the links that you already checked out, that would be great for the community, since they would know which ones are already tested and didn't work. That way, it would narrow down the search for possible issues. Cheers! – AL. May 21 '18 at 07:51
  • Hi, and thank you for your help. I've added the body of the message that I receive. I don't know if that makes it a data only or not though. Also, if I changed the PN icon to something round, I see a white circle instead of a white square. Both images are transparent though – TooManyEduardos May 21 '18 at 16:18

0 Answers0