X-SLAYER / notification_listener_service

Flutter plugin to listen to all incoming notifications (posted or removed) with the possibility to reply to them
https://pub.dev/packages/notification_listener_service
MIT License
21 stars 25 forks source link

EXCEPTION CAUGHT BY SERVICES LIBRARY #15

Closed sabeelmuttil closed 11 months ago

sabeelmuttil commented 11 months ago

@X-SLAYER In my case error showing like this

═╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ╞══════════════════════════════════════════════════════════
The following PlatformException was thrown while activating platform stream on channel
x-slayer/notifications_event:
PlatformException(error, com.payx.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be
specified when a receiver isn't being registered exclusively for system broadcasts, null, null)

When the exception was thrown, this was the stack:
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
message_codecs.dart:652
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
platform_channel.dart:310
<asynchronous suspension>
#2      EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:652:9)
platform_channel.dart:652
<asynchronous suspension>
════════════════════════════════════════
<service
    android:label="notifications"
    android:name="notification.listener.service.NotificationListener"
    android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
    android:exported="false">
    <intent-filter>
        <action android:name="android.service.notification.NotificationListenerService" />
    </intent-filter>
</service>
sabeelmuttil commented 11 months ago

Currently notification is not receiving

X-SLAYER commented 11 months ago

Any code I can run to try this?

sabeelmuttil commented 11 months ago

@X-SLAYER This is the code I'm trying to run.

Future<void> startListening() async {
    /// check if notification permession is enebaled
    bool status = await NotificationListenerService.isPermissionGranted();

    if (!status) {
      /// request notification permission
      /// it will open the notifications settings page and return `true` once -
      /// the permission granted.
      status = await NotificationListenerService.requestPermission();
    }

    log('status $status');

    /// stream the incoming notification events
    NotificationListenerService.notificationsStream
        .listen((ServiceNotificationEvent event) {
      log('packageName $event');
      if (event.hasRemoved != true) {
        forgroundMessageHandler(event);
      }
    });
  }

and this is the version I'm using

Flutter 3.13.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 12fccda598 (8 weeks ago) • 2023-09-19 13:56:11 -0700
Engine • revision bd986c5ed2
Tools • Dart 3.1.2 • DevTools 2.25.0
sabeelmuttil commented 11 months ago

@X-SLAYER r u checked?

X-SLAYER commented 11 months ago

Did you try the example folder code? it works fine for me I tested it on a real device and an emulator + run the example code and check

sabeelmuttil commented 11 months ago

same error ======== Exception caught by services library ====================================================== The following PlatformException was thrown while activating platform stream on channel x-slayer/notifications_event: PlatformException(error, com.payx.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts, null, null)

When the exception was thrown, this was the stack:

0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)

1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)

#2 EventChannel.receiveBroadcastStream. (package:flutter/src/services/platform_channel.dart:652:9) ====================================================================================================
sabeelmuttil commented 11 months ago

@X-SLAYER Could you pls publish the latest changes

X-SLAYER commented 11 months ago

WHat phone did you try one wich android version ?

sabeelmuttil commented 11 months ago

emulator Pixal 3a Android 14

sabeelmuttil commented 11 months ago

and also redmi note pro android 11 not working

X-SLAYER commented 11 months ago

i think it's problem with android 14 I will fix it asap

sabeelmuttil commented 11 months ago

okay pls let me know once it is completed

X-SLAYER commented 11 months ago

Can you try the updated example folder before I publish the new version

sabeelmuttil commented 11 months ago

@X-SLAYER Thanks this is working, but you need to change it a little bit

in android/build.gradle

compileSdkVersion 34
to 
compileSdk 34

in onListen

context.registerReceiver(notificationReceiver, intentFilter);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
    context.registerReceiver(notificationReceiver, intentFilter, Context.RECEIVER_EXPORTED);
}else{
    context.registerReceiver(notificationReceiver, intentFilter);
}

to

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
    context.registerReceiver(notificationReceiver, intentFilter, Context.RECEIVER_EXPORTED);
}else{
    context.registerReceiver(notificationReceiver, intentFilter);
}
X-SLAYER commented 11 months ago

New version is published notification_listener_service: ^0.3.3