Kodala Parth
Kodala Parth

Reputation: 273

Notification channel 'basic_channel' does not exist., n.a.a.k.f.a:

As per flutter package I implemented code on my project but it threw exception while making build, "Notification channel 'call_channel' does not exist., n.a.a.k.f.a:". I don't understand why it's happen?

Here is my code.

  WidgetsFlutterBinding.ensureInitialized();
  await AwesomeNotifications().initialize(
      'resource://drawable/ic_launcher',
      [
        NotificationChannel(
            channelGroupKey: 'category_tests',
            channelKey: 'call_channel',
            channelName: 'Calls Channel',
            channelDescription: 'Channel with call ringtone',
            defaultColor: Color(0xFF9D50DD),
            importance: NotificationImportance.Max,
            ledColor: Colors.white,
            channelShowBadge: true,
            locked: true,
            defaultRingtoneType: DefaultRingtoneType.Ringtone),
      ],
      channelGroups: [
        NotificationChannelGroup(
          channelGroupkey: 'category_tests',
          channelGroupName: 'Category tests',
        )
      ],
      debug: true);
  await Firebase.initializeApp();


///Exception occure while run Api.  
I/flutter ( 5032): PlatformException(createNewNotification, Notification channel 'basic_channel' does not exist., n.a.a.k.f.a: Notification channel 'basic_channel' does not exist.
I/flutter ( 5032):  at n.a.a.k.i.g.i(:5)
I/flutter ( 5032):  at n.a.a.k.i.k.i(Unknown Source:4)
I/flutter ( 5032):  at n.a.a.k.d.b(Unknown Source:10)
I/flutter ( 5032):  at n.a.a.f.f(:2)
I/flutter ( 5032):  at n.a.a.f.onMethodCall(:42)
I/flutter ( 5032):  at l.a.d.a.w.a(Unknown Source:17)
I/flutter ( 5032):  at io.flutter.embedding.engine.n.g.e(Unknown Source:17)
I/flutter ( 5032):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(Unknown Source:4)
I/flutter ( 5032):  at android.os.MessageQueue.nativePollOnce(Native Method)
I/flutter ( 5032):  at android.os.MessageQueue.next(MessageQueue.java:335)
I/flutter ( 5032):  at android.os.Looper.loopOnce(Looper.java:161)
I/flutter ( 5032):  at android.os.Looper.loop(Looper.java:288)
I/flutter ( 5032):  at android.app.ActivityThread.main(ActivityThread.java:7839)
I/flutter ( 5032):  at java.lang.reflect.Method.invoke(Native Method)
I/flutter ( 5032):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
I/flutter ( 5032):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
I/flutter ( 5032): , null)
Exited

Upvotes: 3

Views: 4610

Answers (1)

khoi
khoi

Reputation: 1180

You have to make sure that channelKey has same name between NotifcationChannel and createNotification Function.

Below is setup notification

AwesomeNotifications().initialize(
        // set the icon to null if you want to use the default app icon
        null,
        [
          NotificationChannel(
              channelGroupKey: 'basic_channel_group',
              channelKey: 'call_channel', /* same name */
              channelName: 'Basic notifications',
              channelDescription: 'Notification channel for basic tests',
              defaultColor: Color(0xFF9D50DD),
              ledColor: Colors.white)
        ],
        // Channel groups are only visual and are not required
        channelGroups: [
          NotificationChannelGroup(
              channelGroupkey: 'basic_channel_group',
              channelGroupName: 'Basic group')
        ],
        debug: true);

    AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
      if (!isAllowed) {
        // This is just a basic example. For real apps, you must show some
        // friendly dialog box before call the request method.
        // This is very important to not harm the user experience
        AwesomeNotifications().requestPermissionToSendNotifications();
      }
    });

    ////Notification Listener
  
  AwesomeNotifications()
        .actionStream
        .listen((ReceivedNotification receivedNotification) {
      Navigator.pushAndRemoveUntil(
        context,
        MaterialPageRoute(builder: (context) => BottomNavBar()),
        (Route<dynamic> route) => false,
      );
    });

Called createNotification function.

Notification is display when this method is called.

  AwesomeNotifications().createNotification(
          content: NotificationContent(
              id: 10,
              channelKey: 'call_channel', /* same name */
              title: 'SMS Alert (${policy?.policyName})',
              body: msg ?? ""));

Upvotes: 3

Related Questions