Android Question [SOLVED] Reading StatusBarNotification's extras

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
I am facing a problem I can't understand.

While trying to read some entries :

(Bundle) Bundle[{android.title=Porto - Lisboa : 18°, android.subText=null, android.showChronometer=false, android.icon=2130838475, android.text=Ensoleillé, android.progress=0, android.progressMax=0, android.showWhen=true, android.rebuild.applicationInfo=ApplicationInfo{dccc5e com.google.android.googlequicksearchbox}, android.largeIcon=android.graphics.Bitmap@12fbd83f, android.infoText=2 cartes, android.originatingUserId=0, android.progressIndeterminate=false}]
I get only :
android.title = null
android.infoText = 2 cartes

But
(Bundle) Bundle[{android.title=‪Casa‪, android.subText=null, android.template=android.app.Notification$BigTextStyle, android.showChronometer=false, android.icon=2130837792, android.text=Test, android.progress=0, android.progressMax=0, android.showWhen=true, android.rebuild.applicationInfo=ApplicationInfo{314955b0 com.android.mms}, android.people=[Ljava.lang.String;@a754c29, android.largeIcon=android.graphics.Bitmap@1dc1bae, android.bigText=Test, android.infoText=null, android.originatingUserId=0, android.progressIndeterminate=false}]
I get that time :
android.title = Casa
android.text = null
android.bigText = null

The code I am using is derived from the NotificationListener example :
B4X:
Sub Listener_NotificationPosted (SBN As StatusBarNotification)
    Log("NotificationPosted, package = " & SBN.PackageName & ", id = " & SBN.Id & _
        ", text = " & SBN.TickerText)
    Dim p As Phone
    If p.SdkVersion >= 19 Then
        Dim jno As JavaObject = SBN.Notification
        Dim extras As JavaObject = jno.GetField("extras")
        extras.RunMethod("size", Null)
        Log(extras)
        Dim title As String = extras.RunMethod("getString", Array As Object("android.title"))
        LogColor("Title = " & title, Colors.Blue)


        Dim StringToGet As List
        StringToGet.Initialize
        StringToGet.AddAll(Array As String("android.title","android.text","android.subText","android.bigText","android.infoText"))
       
        For loopMe=0 To StringToGet.Size-1
            Log($" ${StringToGet.Get(loopMe)} = ${extras.RunMethod("getString", Array As Object(StringToGet.Get(loopMe)))} "$)
        Next

    End If
End Sub

Please do you see why I can't get the values by fields depending on the notification ?
If I can not access the extras by field, how could I get the whole extras string to parse it ?

Many thanks
 
Top