flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_messaging] set notification channel id (notification in background Not working)

Open MahmoodBakhshayesh opened this issue 7 years ago • 56 comments

Describe the bug the function onResume and onLunch not working on android platform, while they work fine on IOS, i receive the following message on console instead of printed strings in those functions:

"W/FirebaseMessaging(24847): Missing Default Notification Channel metadata in AndroidManifest. Default value will be used."

onMessage function works fine, the problem is when the app is in background

To Reproduce try to print something in onResume and onLunch functions

Expected behavior the functions be called on work fine as they do on IOS

Additional context my guess is that it has something to do with android notification channel id which should be added in android manifest

when i add that to manifest the message change to : "Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used."

MahmoodBakhshayesh avatar Sep 04 '19 07:09 MahmoodBakhshayesh

@MahmoodBakhshayesh Thanks for flagging this, looks like we don't currently have support for message channels. We should add this.

Feel free to submit a PR if you have a solution.

kroikie avatar Sep 04 '19 18:09 kroikie

https://github.com/FirebaseExtended/flutterfire/issues/47 https://github.com/FirebaseExtended/flutterfire/pull/53 https://github.com/FirebaseExtended/flutterfire/issues/116 https://github.com/FirebaseExtended/flutterfire/issues/125

iapicca avatar Oct 24 '19 09:10 iapicca

Any clear documents to setup firebase messaging? I follow 5.1.6 instruction. Facing the above issue

AkoWu101 avatar Nov 01 '19 06:11 AkoWu101

Any updates?

Masaokb avatar Nov 05 '19 03:11 Masaokb

Any update for this issue..? or it will be fix when stable version updated???

digarahayu avatar Nov 25 '19 11:11 digarahayu

Any update for this issue..?

hiuryanderson avatar Dec 04 '19 21:12 hiuryanderson

Any updates for this?

JemZubiri-Projects avatar Dec 11 '19 07:12 JemZubiri-Projects

Is there any update for this issue?

Navil avatar Mar 08 '20 18:03 Navil

any update?

bhanuka96 avatar Mar 09 '20 04:03 bhanuka96

Did someone find a workaround for this issue? Thanks

EzequielMoroni avatar Mar 11 '20 23:03 EzequielMoroni

Does anyone have a solution?

faldunate avatar Mar 18 '20 00:03 faldunate

I had the problem that the method registered with "onBackgroundMessage" was not called. Here I found that if the message sent from my Nodejs backend had a "notification" entity, the "onBackgroundMessage" was not called. Only the "data" entity may be contained here.

Wrong way:

const message = {
  token: 'myToken',
  notification:{
    title: 'My Title',
    body: 'The body data',
  },
  data: {
    time: 'My data',
    value: '2',
  }
}

Right way:

const message = {
  token: 'myToken',
  data: {
    time: 'My data',
    value: '2',
  }
}

If I send the "right way" message, background function will be called.

It could be the solution for #1269

fl-oe avatar Mar 23 '20 19:03 fl-oe

adding this to my sent data worked for me 'click_action': 'FLUTTER_NOTIFICATION_CLICK'

ajnaf avatar Apr 07 '20 01:04 ajnaf

Hi @MahmoodBakhshayesh did @ajnaf solution worked for you? Thank you

iapicca avatar Apr 08 '20 11:04 iapicca

Hey, I am also facing the same issue. I can confirm that:

adding this to my sent data worked for me 'click_action': 'FLUTTER_NOTIFICATION_CLICK'

does not solve this issue.

ayush221b avatar Apr 21 '20 14:04 ayush221b

Hello, just to give some insight on this.

That message is a information message only. If no channel is specified via your Android manifest then FCM creates & uses it's own notification channel (since they're required in later Android versions). The channel is only used to impact how the notification is shown - from memory this is a default priority notification with sound enabled.

If you created a custom channel (via https://pub.dev/packages/flutter_local_notifications for example), you could specify that channel ID in the manifest and the notification would use your custom one.

If you provide a channel ID to the notification and it doesn't exist on the device, FCM falls back to it's own channel (and you see that message).

Our plan is to make this more user-friendly to work with, however for now you can safely ignore this message. I'll leave open to track though.

Ehesp avatar Apr 22 '20 07:04 Ehesp

@Ehesp As you mentioned if no channel is specified then FCM should create and use its own notification channel, hence while sending the notification to the app, if we do not include an Android Notification Channel param then the it should be attributed to the default channel that FCM has created, but that that is not the case. When I do not specify any custom notification channel in my project and send a notification without the Android Notification Channel param even then I get this error when the app is not in foreground.

ayush221b avatar Apr 22 '20 12:04 ayush221b

@ayush221b it's not an error, it's just a message from FCM telling you it's using it's own channel. You can get around this for now by creating your own channel and assigning the channel ID to the message body when you send it from the server.

Ehesp avatar Apr 22 '20 12:04 Ehesp

I had the problem that the method registered with "onBackgroundMessage" was not called. Here I found that if the message sent from my Nodejs backend had a "notification" entity, the "onBackgroundMessage" was not called. Only the "data" entity may be contained here.

Wrong way:

const message = {
  token: 'myToken',
  notification:{
    title: 'My Title',
    body: 'The body data',
  },
  data: {
    time: 'My data',
    value: '2',
  }
}

Right way:

const message = {
  token: 'myToken',
  data: {
    time: 'My data',
    value: '2',
  }
}

If I send the "right way" message, background function will be called.

It could be the solution for #1269

hello, i've deleted the the notification and it still doesnt read my onbackgroundmessagehandler, what do i do

azheennn avatar May 31 '20 18:05 azheennn

Hello,

I've reading a lot of comments since 6 months and still cannot figure out how to make onBackgroundMessage working. OnLaunch, OnResume and OnMessage works perfectly. If onBackgroundMessage still not working I will have to change framework :(

Someone successed to deal with it ? A sample app ?

Thanks you

QuentinSc avatar Jul 12 '20 14:07 QuentinSc