Read Other Application Status Bar Notification When User made an interaction with the app

0

I made an android application (using kotlin) that read Youtube music's Status Bar Notification. I am using onNotificationPosted() in NotificationListenerService() to get Status Bar Notification info.

The app successfully returns the title and singer when I pressed any button on the Youtube Music Status Bar Notification button; however, I want to get all the information on the Status Bar Notification when the user interacts with it.

For example, when the user presses any button on the youtube music notification (as you can see in this picture), I want my app to return (1) what button the user pressed and (2) what time the music at (in the picture the music is at "00:21")

    const val YOUTUBE_PACK_NAME = "com.google.android.apps.youtube.music"
    class YoutubeNotificationReader: NotificationListenerService() {
            private val TAG = "YoutubeNotification"
        
        override fun onNotificationPosted(sbn: StatusBarNotification?) {
            super.onNotificationPosted(sbn)
            var packageName: String = sbn!!.packageName
            var notification = sbn!!.notification
            var describeContents = notification.bubbleMetadata
            var extra = notification.extras
            var actions = notification.actions
            var title = extra.getCharSequence(Notification.EXTRA_TITLE)
            var subText = extra.getCharSequence(Notification.EXTRA_SUB_TEXT)
            var text = extra.getCharSequence(Notification.EXTRA_TEXT)
            var summary = extra.getCharSequence(Notification.EXTRA_SUMMARY_TEXT)
            var info = extra.getCharSequence(Notification.EXTRA_INFO_TEXT)
            var category = notification.category
            var catProgress = extra.getCharSequence(Notification.CATEGORY_PROGRESS)
            var audio = extra.get(Notification.EXTRA_AUDIO_CONTENTS_URI)
            var keys = notification.sortKey
    
        if(packageName == YOUTUBE_PACK_NAME) {
            Log.d(TAG, "onNotificationPosted: $packageName")
            Log.d(TAG, "Describe: $describeContents")
            Log.d(TAG, "Notification toString ${notification.toString()}")
            Log.d(TAG, "title $title")
            Log.d(TAG, "text $text")
            Log.d(TAG, "subtext $subText")
            Log.d(TAG, "action: $actions")
            Log.d(TAG, "Summary: $summary")
            Log.d(TAG, "info: $info")
            Log.d(TAG, "audio: $audio")
            Log.d(TAG, "Category progress: $catProgress")
            Log.d(TAG, "Keys: $keys")
            Log.d(TAG, "Return Extra: ${extra.toString()}")
            Log.d(TAG, "Return Media: ${extra.get(Notification.EXTRA_MEDIA_SESSION)}")
        }
    }
}

This code returns only the followings:

When I pressed PLAY
2020-12-04 00:35:20.167 948-948/com.example.readnotification D/YoutubeNotification: onNotificationPosted: com.google.android.apps.youtube.music
2020-12-04 00:35:20.167 948-948/com.example.readnotification D/YoutubeNotification: Describe: null
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: Notification toString Notification(channel=7 shortcut=null contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x62 color=0x00000000 category=transport actions=5 vis=PUBLIC)
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: title Sunflower (Spider-Man: Into the Spider-Verse)
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: text Post Malone, Swae Lee & Swae Lee
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: subtext null
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: action: [Landroid.app.Notification$Action;@807da81
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: Summary: null
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: info: null
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: audio: null
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: Category progress: null
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: Keys: null
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: Return Extra: Bundle[{android.title=Sunflower (Spider-Man: Into the Spider-Verse), android.reduced.images=true, android.subText=null, android.template=android.app.Notification$MediaStyle, android.showChronometer=false, android.text=Post Malone, Swae Lee & Swae Lee, android.progress=0, android.progressMax=0, android.appInfo=ApplicationInfo{b18726 com.google.android.apps.youtube.music}, android.showWhen=false, android.largeIcon=Icon(typ=BITMAP size=176x176), android.infoText=null, android.mediaSession=android.media.session.MediaSession$Token@64157fa, android.progressIndeterminate=true, android.remoteInputHistory=null, android.compactActions=[1, 2, 3]}]
2020-12-04 00:35:20.168 948-948/com.example.readnotification D/YoutubeNotification: Return Media: android.media.session.MediaSession$Token@64157fa
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: onNotificationPosted: com.google.android.apps.youtube.music
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: Describe: null
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: Notification toString Notification(channel=7 shortcut=null contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x62 color=0x00000000 category=transport actions=5 vis=PUBLIC)
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: title Sunflower (Spider-Man: Into the Spider-Verse)
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: text Post Malone, Swae Lee & Swae Lee
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: subtext null
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: action: [Landroid.app.Notification$Action;@a056114
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: Summary: null
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: info: null
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: audio: null
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: Category progress: null
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: Keys: null
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: Return Extra: Bundle[{android.title=Sunflower (Spider-Man: Into the Spider-Verse), android.reduced.images=true, android.subText=null, android.template=android.app.Notification$MediaStyle, android.showChronometer=false, android.text=Post Malone, Swae Lee & Swae Lee, android.progress=0, android.progressMax=0, android.appInfo=ApplicationInfo{1569dbd com.google.android.apps.youtube.music}, android.showWhen=false, android.largeIcon=Icon(typ=BITMAP size=176x176), android.infoText=null, android.mediaSession=android.media.session.MediaSession$Token@64157fa, android.progressIndeterminate=true, android.remoteInputHistory=null, android.compactActions=[1, 2, 3]}]
2020-12-04 00:35:20.356 948-948/com.example.readnotification D/YoutubeNotification: Return Media: android.media.session.MediaSession$Token@64157fa
When I pressed pause
2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: onNotificationPosted: com.google.android.apps.youtube.music
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: Describe: null
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: Notification toString Notification(channel=7 shortcut=null contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x0 color=0x00000000 category=transport actions=5 vis=PUBLIC)
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: title Sunflower (Spider-Man: Into the Spider-Verse)
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: text Post Malone, Swae Lee & Swae Lee
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: subtext null
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: action: [Landroid.app.Notification$Action;@31eefb2
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: Summary: null
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: info: null
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: audio: null
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: Category progress: null
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: Keys: null
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: Return Extra: Bundle[{android.title=Sunflower (Spider-Man: Into the Spider-Verse), android.reduced.images=true, android.subText=null, android.template=android.app.Notification$MediaStyle, android.showChronometer=false, android.text=Post Malone, Swae Lee & Swae Lee, android.progress=0, android.progressMax=0, android.appInfo=ApplicationInfo{6e07b03 com.google.android.apps.youtube.music}, android.showWhen=false, android.largeIcon=Icon(typ=BITMAP size=176x176), android.infoText=null, android.mediaSession=android.media.session.MediaSession$Token@64157fa, android.progressIndeterminate=true, android.remoteInputHistory=null, android.compactActions=[1, 2, 3]}]
    2020-12-04 00:35:33.526 948-948/com.example.readnotification D/YoutubeNotification: Return Media: android.media.session.MediaSession$Token@64157fa
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: onNotificationPosted: com.google.android.apps.youtube.music
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: Describe: null
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: Notification toString Notification(channel=7 shortcut=null contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x0 color=0x00000000 category=transport actions=5 vis=PUBLIC)
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: title Sunflower (Spider-Man: Into the Spider-Verse)
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: text Post Malone, Swae Lee & Swae Lee
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: subtext null
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: action: [Landroid.app.Notification$Action;@dd458b9
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: Summary: null
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: info: null
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: audio: null
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: Category progress: null
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: Keys: null
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: Return Extra: Bundle[{android.title=Sunflower (Spider-Man: Into the Spider-Verse), android.reduced.images=true, android.subText=null, android.template=android.app.Notification$MediaStyle, android.showChronometer=false, android.text=Post Malone, Swae Lee & Swae Lee, android.progress=0, android.progressMax=0, android.appInfo=ApplicationInfo{e8854fe com.google.android.apps.youtube.music}, android.showWhen=false, android.largeIcon=Icon(typ=BITMAP size=176x176), android.infoText=null, android.mediaSession=android.media.session.MediaSession$Token@64157fa, android.progressIndeterminate=true, android.remoteInputHistory=null, android.compactActions=[1, 2, 3]}]
    2020-12-04 00:35:33.732 948-948/com.example.readnotification D/YoutubeNotification: Return Media: android.media.session.MediaSession$Token@64157fa
android
kotlin
asked on Stack Overflow Dec 4, 2020 by Taejoon Park

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0