For Android 9 or above use this:

    adb shell cmd notification allow_listener com.mypackage.app/com.mypackage.app.mylistener

For any other Android version below 9 use this: 

    adb shell settings put secure enabled_notification_listeners %nlisteners: com.example.myapplication/com.example.myapplication.service.ServiceNotificationIntercept