use
adb shell cmd notification allow_listener com.mypackage.app/com.mypackage.app.mylistener
in android 9 and above
For below 9,
adb shell settings put secure enabled_notification_listeners %nlisteners: com.example.myapplication/com.example.myapplication.service.ServiceNotificationIntercept