Notification.Extra.GetString returns empty while it contains data

蹲街弑〆低调 提交于 2019-12-11 06:17:30

问题


I have a NotificationListener for my app that is supposed to listen to media player notifications like Spotify or GPM. This is the code for the OnListenerConnected override:

public override void OnListenerConnected()
        {
            base.OnListenerConnected();

            Log.WriteLine(LogPriority.Info, "SmartLyrics", "OnListenerConnected (NLService): Listener connected");

            foreach (StatusBarNotification sbn in GetActiveNotifications())
            {
                if (sbn.Notification.Category == "transport")
                {
                    Log.WriteLine(LogPriority.Info, "SmartLyrics", "EXTRAS " + sbn.Notification.Extras.ToString());

                    Log.WriteLine(LogPriority.Verbose, "SmartLyrics", "Song Title - " + sbn.Notification.Extras.GetString("android.title"));
                    Log.WriteLine(LogPriority.Verbose, "SmartLyrics", "Song Artist - " + sbn.Notification.Extras.GetString("android.text"));
                }
            }
        }

The problem is that this is what I recieve in the LogCat:

06-18 23:36:05.405: I/SmartLyrics(25456): EXTRAS Bundle[{android.title=Kimigaite Mizuninaru, android.reduced.images=true, 
android.subText=Tadashii Itsuwarikarano Kishou, android.template=android.app.Notification$MediaStyle, 
android.showChronometer=false, android.icon=2130838406, 
android.text=ZUTOMAYO, android.progress=0, 
android.progressMax=0, android.appInfo=ApplicationInfo{34055c8 com.google.android.music} //... it goes on for a bit more}]
06-18 23:36:05.405: V/SmartLyrics(25456): Song Title - Kimigaite Mizuninaru
06-18 23:36:05.406: V/SmartLyrics(25456): Song Artist - ZUTOMAYO

06-18 23:36:05.516: I/SmartLyrics(25456): EXTRAS Bundle[{android.title=Veridis Quo, android.reduced.images=true, 
android.subText=Songs, android.template=android.app.Notification$MediaStyle, 
android.showChronometer=false, android.icon=2131231377, 
android.text=Daft Punk, android.progress=0, 
android.progressMax=0, android.appInfo=ApplicationInfo{8ca15e0 com.spotify.music} //... it goes on for a bit more}]
06-18 23:36:05.517: V/SmartLyrics(25456): Song Title - 
06-18 23:36:05.517: V/SmartLyrics(25456): Song Artist - 

(edited slightly for readability) You can see that it gets the notifications for both Google Play Music and Spotify, but even though the Extras.ToString() shows that android.title and android.text have values, the ``GetString` method doesn't show anything on the log.

I really have no idea what I going on. I thought about maybe using a RegEx to cut down the Extras.ToString() only to what I need but that doesn't look like a good solution. Any help here?

EDIT: To clarify that this is consistent, I've tested multiple times with YouTube Vanced, GPM and Spotify and only GPM prints the information on the log.

来源:https://stackoverflow.com/questions/56659371/notification-extra-getstring-returns-empty-while-it-contains-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!