Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MahmoodBakhshayesh opened this issue Sep 4, 2019 · 56 comments
Assignees
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) platform: android Issues / PRs which are specifically for Android. plugin: messaging type: documentation Improvements or additions to documentation type: enhancement New feature or request

Comments

@MahmoodBakhshayesh
Copy link

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 MahmoodBakhshayesh added the type: bug Something isn't working label Sep 4, 2019
@kroikie kroikie changed the title [<FIREBASE_MESSAGING>] <set notification channel id (notification in background Not working)> [FIREBASE_MESSAGING] set notification channel id (notification in background Not working) Sep 4, 2019
@kroikie
Copy link
Collaborator

kroikie commented Sep 4, 2019

@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.

@BondarenkoStas BondarenkoStas added the type: enhancement New feature or request label Oct 23, 2019
@BondarenkoStas BondarenkoStas added impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) and removed type: bug Something isn't working labels Oct 23, 2019
@iapicca
Copy link

iapicca commented Oct 24, 2019

#47
#53
#116
#125

@iapicca iapicca changed the title [FIREBASE_MESSAGING] set notification channel id (notification in background Not working) [firebase_messaging] set notification channel id (notification in background Not working) Oct 24, 2019
@KingWu
Copy link

KingWu commented Nov 1, 2019

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

@Masaokb
Copy link

Masaokb commented Nov 5, 2019

Any updates?

@digarahayu
Copy link

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

@hiuryanderson
Copy link

Any update for this issue..?

@JemZubiri-Projects
Copy link

Any updates for this?

@Navil
Copy link

Navil commented Mar 8, 2020

Is there any update for this issue?

@bhanuka96
Copy link

any update?

@EzequielMoroni
Copy link

Did someone find a workaround for this issue? Thanks

@bhanuka96
Copy link

bhanuka96 commented Aug 7, 2020

@NoeLopez are you sure? is it only support for topic? okay, but how group notification works on like whatsapp/gmail?
I think you talk about the device group.

@NoeLopez
Copy link

NoeLopez commented Aug 7, 2020

@bhanuka96 Do you mean that notifications are grouped when they arrive?

@deep01code
Copy link

@NoeLopez I still get this error :(
W/FirebaseMessaging( 6367): Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used.

@bhanuka96
Copy link

@bhanuka96 Do you mean that notifications are grouped when they arrive?

yes like this https://developer.android.com/training/notify-user/group . if "A" user sent multiple messages to the "B" user. currently, there are lots of notifications came to in my notification panel, I want to group notification for that. (it's mean like above image like gmail/whatsapp). if "C" user sent multiple message to the "B user". I want to 2 groups

@NoeLopez
Copy link

NoeLopez commented Aug 7, 2020

@bhanuka96 Those types of implementations would have to be done with Local Notification

@NoeLopez
Copy link

NoeLopez commented Aug 7, 2020

@deep01code It would be nice to be able to see your code to see where it goes wrong, remember to add it in Java class and in Android Manifest

@bhanuka96
Copy link

@bhanuka96 Those types of implementations would have to be done with Local Notification

I tried, not working on foreground or background... I saw this react native answer about same issue. I think this part of the firebase_messaging plugin right? invertase/react-native-firebase#449 (comment)

@NoeLopez
Copy link

NoeLopez commented Aug 7, 2020

@bhanuka96 Apparently it seems like if it's a Firebase issue I'm really sorry I can't help you

@braysonjohn148
Copy link

braysonjohn148 commented Aug 7, 2020

I followed exactly the tutorials on youtube on how to setup these notification, they don't do these staffs but they get notifications when the app is teriminated. I don't know what wrong with my code.

firebase_messaging: ^6.0.16

_backgroundMessageHandler i even tried calling FlutterLocalNotificationsPlugin, still don't show notifications when the app is terminated.

`

        <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id"/>`

@NoeLopez
Copy link

NoeLopez commented Aug 7, 2020

@braysonjohn148 If want to be notified in your app (via onResume and onLaunch, see below) when the user clicks on a notification in the system tray include the following intent-filter within the <activity> tag of your android/app/src/main/AndroidManifest.xml:

<intent-filter>
     <action android:name="FLUTTER_NOTIFICATION_CLICK" />
     <category android:name="android.intent.category.DEFAULT" />
 </intent-filter>

Optionally handle background messages

Background message handling is intended to be performed quickly. Do not perform long running tasks as they may not be allowed to finish by the Android system

By default background messaging is not enabled. To handle messages in the background:

  1. Add the com.google.firebase:firebase-messaging dependency in your app-level build.gradle file that is typically located at <app-name>/android/app/build.gradle.
dependencies {
  // ...

  implementation 'com.google.firebase:firebase-messaging:20.2.4'
}

you can find out what the latest version of the plugin is here

  1. Add an Application.java class to your app in the same directory as your MainActivity.java. This is typically found in <app-name>/android/app/src/main/java/<app-organization-path>/.
package com.domain.myapplication;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

public class Application extends FlutterApplication implements PluginRegistrantCallback {
  @Override
  public void onCreate() {
    super.onCreate();
    FlutterFirebaseMessagingService.setPluginRegistrant(this);
  }

  @Override
  public void registerWith(PluginRegistry registry) {
 FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
  }
}
  1. In Application.java, make sure to change package com.domain.myapplication; to your package's identifier. Your package's identifier should be something like com.domain.myapplication for your application package

  2. Set name property of application in AndroidManifest.xml. This is typically found in <app-name>/android/app/src/main/.

<application android:name=".Application" ...>

and the json that sends from Postman or from firebase in the data part has to go this, very important

"click_action": "FLUTTER_NOTIFICATION_CLICK"

Aquí hay un ejemplo del cuerpo de un JSON que debe enviarse desde Postman

{
  "notification": {
    "body": "here you put the body of the message",
    "title": "here you put some title"
  },
  "priority": "high",
  "data": {
    "click_action": "FLUTTER_NOTIFICATION_CLICK",
    "other_data": "any message",
    .....
  },
  "to": "your token ......"
}

Hope this answer can help you solve your problem. Regards

@braysonjohn148
Copy link

what i want is when an app is completely terminated. Meaning the phone is either in the pocket or user on other apps. When a new notification arrives the user to get a push notification even when the app is terminated. Currently when i close the app and send the notification. I cannot see the notification in the system tray. I even tried using the firebase console FCM to fire test messages on my app

@NoeLopez
Copy link

NoeLopez commented Aug 7, 2020

@braysonjohn148 that is done in the onLaunch method (it is when the app has closed completely) and onResume is when the app is in the background, you just have to implement there the actions you want it to do

@Hakim-Allaoui
Copy link

Hakim-Allaoui commented Aug 19, 2020

@braysonjohn148 If want to be notified in your app (via onResume and onLaunch, see below) when the user clicks on a notification in the system tray include the following intent-filter within the <activity> tag of your android/app/src/main/AndroidManifest.xml:

<intent-filter>
     <action android:name="FLUTTER_NOTIFICATION_CLICK" />
     <category android:name="android.intent.category.DEFAULT" />
 </intent-filter>

Optionally handle background messages

Background message handling is intended to be performed quickly. Do not perform long running tasks as they may not be allowed to finish by the Android system

By default background messaging is not enabled. To handle messages in the background:

  1. Add the com.google.firebase:firebase-messaging dependency in your app-level build.gradle file that is typically located at <app-name>/android/app/build.gradle.
dependencies {
  // ...

  implementation 'com.google.firebase:firebase-messaging:20.2.4'
}

you can find out what the latest version of the plugin is here

  1. Add an Application.java class to your app in the same directory as your MainActivity.java. This is typically found in <app-name>/android/app/src/main/java/<app-organization-path>/.
package com.domain.myapplication;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

public class Application extends FlutterApplication implements PluginRegistrantCallback {
  @Override
  public void onCreate() {
    super.onCreate();
    FlutterFirebaseMessagingService.setPluginRegistrant(this);
  }

  @Override
  public void registerWith(PluginRegistry registry) {
 FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
  }
}
  1. In Application.java, make sure to change package com.domain.myapplication; to your package's identifier. Your package's identifier should be something like com.domain.myapplication for your application package
  2. Set name property of application in AndroidManifest.xml. This is typically found in <app-name>/android/app/src/main/.

<application android:name=".Application" ...>

and the json that sends from Postman or from firebase in the data part has to go this, very important

"click_action": "FLUTTER_NOTIFICATION_CLICK"

Aquí hay un ejemplo del cuerpo de un JSON que debe enviarse desde Postman

{
  "notification": {
    "body": "here you put the body of the message",
    "title": "here you put some title"
  },
  "priority": "high",
  "data": {
    "click_action": "FLUTTER_NOTIFICATION_CLICK",
    "other_data": "any message",
    .....
  },
  "to": "your token ......"
}

Hope this answer can help you solve your problem. Regards

Thank you save my day 😍😍

@yourshinsuke
Copy link

yourshinsuke commented Aug 24, 2020

Where is default_notification_channel_id?
It is FLUTTER. Why don't you describe about it?

android/app/src/main/res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="default_notification_channel_id" translatable="false">fcm_default_channel</string>
</resources>

@yourshinsuke
Copy link

E/FlutterFcmService(18015): Fatal: failed to find callback

@fazil-augr
Copy link

same issue is facing from me also

@danilomna
Copy link

Yes of course,

In the Application file that flutter recommends you add a globar variable that will be the name of your id channel, for example

public static final String CHANNEL_HIGH = "channel1";

where channel1 is the id channel, then you create a method like the following

private void createNotificationChannels() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channelHigh = new NotificationChannel(
                    CHANNEL_HIGH,
                    "Notificación Importante",
                    NotificationManager.IMPORTANCE_HIGH
            );

            channelHigh.setDescription("Canal Alto");

            NotificationManager manager = getSystemService(NotificationManager.class);
            manager.createNotificationChannel(channelHigh);

        }
    }

where Notificacion Importante is the name that will appear in the notification settings on the cell phone, then add I'm in the AndroidManifest

<application
        android:name=".Application"
        android:icon="@mipmap/ic_launcher"
        android:label="NotificacionPush">

        <activity
            android:name=".MainActivity" ...
           .......


   <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="channel1"/>

</application>

Note that in android:value it must be the name of the channel ID, which you created in your public variable in the application class.

and with that the notifications will come out with bubble

Hi @NoeLopez , does this solve the onBackgroundMessage callback issue? Could you help with a full project example on github?

@danilomna
Copy link

still happen! onBackgroundMessage still not working

hi @Gperez88 have you found a fix for this issue? It is not working for me too.

@danilomna
Copy link

Does anybody found a workaround or fix to make onBackgroundMessage work?

@danilomna
Copy link

@NoeLopez I still get this error :(
W/FirebaseMessaging( 6367): Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used.

hi @deep01code have you found a fix for this issue? It is not working for me too.

@naveenkumardot25
Copy link

Check this.

Firebase Cloud Messaging link --- https://firebase.google.com/docs/cloud-messaging/android/receive#backgrounded

Screenshot 2020-09-03 at 1 19 13 PM

@yourshinsuke
Copy link

What is this?

[6.0.13] Missing Default Notification Channel metadata in AndroidManifest #2266
Missing Default Notification Channel metadata in AndroidManifest. Default value will be used #343

@naveenkumardot25
Copy link

naveenkumardot25 commented Sep 11, 2020

@yourshinsuke @danilomna

In order to get ride of this, you need to create android notification channel to your app.

Go to this link for more details -- https://developer.android.com/training/notify-user/channels

I have uploaded to Github repository -- https://github.com/Stone2517/Truact-1

AndroidManifest.xml

<application>
      <activity>
           .........
      </activity>
      <meta-data 
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id"/>  ----- Add this.
 </application>

Application.java

public class Application extends FlutterApplication implements PluginRegistrantCallback {
    @Override
    public void onCreate() {
        super.onCreate();
        this.createChannel();   ----- Add this.
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

    @Override
    public void registerWith(PluginRegistry registry) {
        io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
        PathProviderPlugin.registerWith(registry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin"));
    }
    private void createChannel(){   ----- Add this.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Create the NotificationChannel
            String name = getString(R.string.default_notification_channel_id);
            NotificationChannel channel = new NotificationChannel(name, "default", NotificationManager.IMPORTANCE_HIGH);
            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.createNotificationChannel(channel);
        }
    }
}

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="default_notification_channel_id">default_notification_channel_id</string>  ----- Add this.
</resources>

@naveenkumardot25
Copy link

E/FlutterFcmService(18015): Fatal: failed to find callback

reinstall the App

@Salakar
Copy link
Member

Salakar commented Nov 4, 2020

Hey all 👋

As part of our roadmap (#2582) we've just shipped a complete rework of the firebase_messaging plugin that aims to solve this and many other issues.

If you can, please try out the dev release (see the migration guide for upgrading and for changes) and if you have any feedback then join in the discussion here.

Given the scope of the rework I'm going to go ahead and close this issue in favor of trying out the latest plugin.

Thanks everyone 🤓

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) platform: android Issues / PRs which are specifically for Android. plugin: messaging type: documentation Improvements or additions to documentation type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests