firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.51k stars 3.92k forks source link

🐛 [Firebase_messaging] Flutter notification image not showing on all devices #6319

Closed febg11 closed 3 years ago

febg11 commented 3 years ago

I have setup a notification to send with a url to an image from firebase functions. This is received by a flutter app using the firebase_messaging package.

The problem is, the image doesn't display on all phones, only some. I originally thought this could be due to image size (was originally 1mb so i compressed the jpg to around 700kb) but it didn't help.

I am testing it on a oneplus 6 (doesnt show) and a oneplus 7t (does show)

Are there any requirements/reasons that anyone knows that could be affecting the image showing in the notification.

markusaksli-nc commented 3 years ago

Hi @febg11 From the FCM api docs https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification

JPEG, PNG, BMP have full support across platforms. Animated GIF and video only work on iOS. WebP and HEIF have varying levels of support across platforms and platform versions. Android has 1MB image size limit.

Does this help? Thank you

febg11 commented 3 years ago

Hi @markusaksli-nc. The picture I was sending did seem to meet those thresholds. It was a jpg that was 750kb. Is there anything else that would cause it not to be received?

markusaksli-nc commented 3 years ago

Well beyond that it depends on both the image hosting platform and native behavior. There should be something relevant logged in either flutter run -v or device logs on logcat when the message is received to point to a specific cause.

If this is a known issue I'd expect to see something about this on https://github.com/firebase/firebase-android-sdk/issues since this should be purely native behavior if the notification payload is handled successfully and the notification shows up.

I doubt this could be coming from our flutter implementation itself, unless this is a fixed issue in a newer version of the underlying Firebase Android SDK.

google-oss-bot commented 3 years ago

Hey @febg11. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

febg11 commented 3 years ago

Hi I am getting a little confused now. If I send the exact image using the firebase console test message it always works. Yet when I send it from code in a Cron it doesn't show up on my device but does on others.

I am sending the Cron version as a topic message but the test message on the console has to be sent as using a device token. Should this make any difference?

febg11 commented 3 years ago

Ok I've just doubled checking the node docs and it seems like they have been updated since I last used them.

I am sending the message like so

{
  notification: {
    body: 'body',
    title: 'title',
    image: 'THE IMAGE LINK'
  },
  data: { click_action: 'FLUTTER_NOTIFICATION_CLICK' },
  topic: 'GENERAL_NOTIFICATION_TOPIC'
} 

Is this still a valid method or does this package only work with the following new method

 {
  notification: {
    title: 'Sparky says hello!'
  },
  android: {
    notification: {
      imageUrl: 'https://foo.bar.pizza-monster.png'
    }
  },
  apns: {
    payload: {
      aps: {
        'mutable-content': 1
      }
    },
    fcm_options: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  webpush: {
    headers: {
      image: 'https://foo.bar.pizza-monster.png'
    }
  },
  topic: topicName,
};

Is apn something to do with Apple devices?

Also I forgot to mention the image links I am sending are signed URLS so are quite long (around 350 characters), could this have any impact?

Sorry about this it's just hard for me to determine whether this is a server side or client side problem

markusaksli-nc commented 3 years ago

Since this is being caused by sending the message in different ways it looks like that could be the issue? Are you sure all of the devices have successfully subscribed to the topic?

Not sure what you mean by "new method". It's not necessary to add the message manually to each of the platform-specific payloads. That's what the general notification key is for and it should work fine. If you have doubts about the length of the URL you can always test with a shorter one.

Since there are outside factors here like where you are sending the message from and using what delivery method I would suggest you contact https://firebase.google.com/support as well. Unless they say it's a client issue, I don't see how this could be caused by our plugin code and since we haven't been able to reproduce I'll close the issue for now. If it turns out to be an issue with the dart wrapper for the native SDK let me know and I'll reopen.

febg11 commented 3 years ago

Hi @markusaksli-nc

The docs seem to be different in places, some saying the key should be image others imageUrl. I have tried with both and still receive no image at times. It doesn't seem to be related to connection speed either, it just doesn't load at times.

Ive managed to use the logcat to receive a notification that was sent with an image that did not display. here is what is says:

/FirebaseMessaging: Unable to log event: analytics library is missing
/FirebaseMessaging: Starting download of: [IMAGE_LINK]
/FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
/FirebaseMessaging: Failed to download image in time, showing notification without it
/StudioTransport: Agent command stream started.
/StudioTransport: Handling agent command 1200 for pid: 4212.
/StudioTransport: JNIEnv not attached

Can anything be done to ensure Failed to download image in time doesn't occur. Is there a timeout or some other config that can be adjusted?

Also is the Missing Default Notification Channel metadata something I should be concerned about?

Thanks a lot


Manged to get a java exception

I/FirebaseMessaging: Starting download of: [IMAGE_LINK]
/FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
/FirebaseMessaging: Failed to download image in time, showing notification without it
/FirebaseMessaging: Failed to close the image download stream.
    java.lang.NullPointerException: Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
        at com.android.okhttp.okio.Buffer.write(Buffer.java:1182)
        at com.android.okhttp.okio.Buffer.read(Buffer.java:1221)
        at com.android.okhttp.okio.RealBufferedSource.read(RealBufferedSource.java:55)
        at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:393)
        at com.android.okhttp.internal.Util.skipAll(Util.java:159)
        at com.android.okhttp.internal.Util.discard(Util.java:141)
        at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.close(Http1xStream.java:410)
        at com.android.okhttp.okio.RealBufferedSource.close(RealBufferedSource.java:396)
        at com.android.okhttp.okio.RealBufferedSource$1.close(RealBufferedSource.java:384)
        at com.google.android.gms.internal.firebase_messaging.zzm.zza(com.google.firebase:firebase-messaging@@22.0.0:1)
        at com.google.firebase.messaging.ImageDownload.close(com.google.firebase:firebase-messaging@@22.0.0:1)
        at com.google.firebase.messaging.DisplayNotification.waitForAndApplyImageDownload(com.google.firebase:firebase-messaging@@22.0.0:5)
        at com.google.firebase.messaging.DisplayNotification.handleNotification(com.google.firebase:firebase-messaging@@22.0.0:5)
        at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@22.0.0:8)
        at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@22.0.0:8)
        at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@22.0.0:3)
        at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@22.0.0:3)
        at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging@@22.0.0:1)
markusaksli-nc commented 3 years ago

Hmm not sure, this is just on the native side so you can open an issue in https://github.com/firebase/firebase-android-sdk/issues about it. Although it might just be caused by an unstable/slow connection? If that is the case you can try to make sure you compress/resize your images to ensure as much coverage as possible.