Android Question How to run method getCharSequenceArray?

jtare

Active Member
Licensed User
Longtime User
I've been using notification listener for a while now and I wonder how to run the method getCharSequenceArray outside of the notificationlistener service. I save the notification textLines in a string variable, but I can't find the way to run getCharSequenceArray to get back an array of strings.
I tried something like this
B4X:
    'textLinesSavedVariable is a string variable
    Private JO As JavaObject
    JO.InitializeContext
    'JO.InitializeStatic("java.lang.Class") 'I tried different classes
    Try
        Dim lines() As Object = JO.RunMethod("getCharSequenceArray", Array(textLinesSavedVariable))
        For Each line As Object In lines
            Log(line)
        Next
    Catch
        'LogColor("Error!", Colors.Red)
        Log(LastException)
    End Try
But always get an method not found error.
As a side note, the saved variable (textLinesSavedVariable) holds this text: [Ljava.lang.CharSequence;@bb00ae
I wonder what [Ljava.lang.CharSequence;@bb00ae means, if it is an address pointing somewhere into the ram memory maybe it would not make sense to save the data because whenever the phone GC delete that, I would not be available to get it back.
 
Last edited:

jtare

Active Member
Licensed User
Longtime User
Based on this thread https://www.b4x.com/android/forum/t...er-library-notificationlistenerservice.35630/ post 16 and 28

In the notification listener I have the following code:
B4X:
Sub Process_Globals
  Private listener As NotificationListener
  Private textLines As String
  'Dim Notifications As List
End Sub

Sub Listener_NotificationPosted (SBN As StatusBarNotification)
  Extras As JavaObject = GetExtras(SBN)
  textLines = Extras.RunMethod("getString", Array As Object("android.textLines"))
End Sub

Public Sub GetExtras(SBN As StatusBarNotification) As JavaObject
  Dim jno As JavaObject = SBN.Notification
If jno.IsInitialized Then
   Dim Extras As JavaObject = jno.GetField("extras")
    Extras.RunMethod("size", Null)
    Return Extras
End If
End Sub

textLines holds [Ljava.lang.CharSequence;@bb00ae
And if I run inside the notification listener service the following code I will be available to get the charSequenceArray with no problem

B4X:
Sub Listener_NotificationPosted (SBN AsStatusBarNotification)
  Extras As JavaObject = GetExtras(SBN)
  textLines = Extras.RunMethod("getString", ArrayAs Object("android.textLines"))
     Try
         Dim lines() As Object = Extras.RunMethod("getCharSequenceArray", Array("android.textLines"))
            For Each line As Object In lines
               Log(line)
            Next
     Catch
                    LogColor("Error!", Colors.Red)
     End Try
End Sub

But when I save the textLines string variable with keyvaluestore
B4X:
starter.kvs.put("Text",textLines)
so I can later use it in my main activity, I can't find the way to get each value of the array, like I did inside the Listener_NotificationPosted function.

I tried what I wrote in post 1, in my main activity
B4X:
'textLinesSavedVariable is a string variable
Private JO As JavaObject
Private textLinesSavedVariable As String = starter.kvs.get("Text")
JO.InitializeContext
'JO.InitializeStatic("java.lang.Class") 'I tried different classes
Try
  Dim lines() As Object = JO.RunMethod("getCharSequenceArray", Array(textLinesSavedVariable))
  For Each line As Object In lines
  Log(line)
  Next
  Catch
  'LogColor("Error!", Colors.Red)
  Log(LastException)
End Try
But I can't get the same result as if I run the code inside the notification service (Listener_NotificationPosted). I always get method not found error.
 
Last edited:
Upvote 0
Top