Android Question [solved] Method getBoundsInWindow not found in android.view.accessibility.AccessibilityNodeInfo

sirjo66

Well-Known Member
Licensed User
Longtime User
Hi,
in my app I use accessibility service

On acs_OnAccessibilityEvent I need to read views properties, so,
based on https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo page (see "Public methods" section)....
B4X:
Dim evento As JavaObject
Dim nodo As JavaObject

Sub acs_OnAccessibilityEvent (Event As Object, Node As Object)
   
    nodo = Node
    evento = Event

    Dim EventType As Int = evento.RunMethod("getEventType", Null).As(Int)
    Dim PackageName As String = evento.RunMethod("getPackageName", Null).As(String)

    Dim nodes As JavaObject = nodo.RunMethod("get", Array As Object(0)) ' get all nodes
    Dim nodesCount As Int = nodes.RunMethod("size", Null).As(Int) ' get the nodes count
   
    For x = 0 To nodesCount - 1
        Dim obj As JavaObject = nodes.RunMethodJO("get", Array As Object(x)) ' get the node
        Dim ViewId As String = obj.RunMethod("getViewIdResourceName", Null).As(String) ' get the ViewId
        Dim ClassName As String = obj.RunMethod("getClassName", Null).As(String)
        Dim isClickable As Boolean = obj.RunMethod("isClickable", Null).As(Boolean)

        ' and so on with other proprieties....
    Next
End Sub

and it works very well !!

But now I want to read also bounds of view, so......
B4X:
        Dim outBounds As JavaObject
        outBounds.InitializeStatic("android.graphics.Rect")
        obj.RunMethod("getBoundsInWindow", Array As Object(outBounds))

but when I "RunMethod" the error is:
java.lang.RuntimeException: Method: getBoundsInWindow not found in: android.view.accessibility.AccessibilityNodeInfo

method not found ????? ?

Why ??

Thanks
Sergio
 
Last edited:
Solution
Rect static? i don't think so. try instantiating it.
rect cannot be null in getBoundsInWindow(). are you sure it isn't?

also - and perhaps irrelevant if i'm correct above - unclear where obj variable is declared.
you already declare obj in your sub, but this second obj doesn't appear there, so you
must be using the same name elsewhere.

drgottjr

Expert
Licensed User
Longtime User
Rect static? i don't think so. try instantiating it.
rect cannot be null in getBoundsInWindow(). are you sure it isn't?

also - and perhaps irrelevant if i'm correct above - unclear where obj variable is declared.
you already declare obj in your sub, but this second obj doesn't appear there, so you
must be using the same name elsewhere.
 
Upvote 0
Solution

sirjo66

Well-Known Member
Licensed User
Longtime User
obj variable is correct, the full source code is
B4X:
Dim evento As JavaObject
Dim nodo As JavaObject

Sub acs_OnAccessibilityEvent (Event As Object, Node As Object)
 
    nodo = Node
    evento = Event

    Dim EventType As Int = evento.RunMethod("getEventType", Null).As(Int)
    Dim PackageName As String = evento.RunMethod("getPackageName", Null).As(String)

    Dim nodes As JavaObject = nodo.RunMethod("get", Array As Object(0)) ' get all nodes
    Dim nodesCount As Int = nodes.RunMethod("size", Null).As(Int) ' get the nodes count
 
    For x = 0 To nodesCount - 1
        Dim obj As JavaObject = nodes.RunMethodJO("get", Array As Object(x)) ' get the node
        Dim ViewId As String = obj.RunMethod("getViewIdResourceName", Null).As(String) ' get the ViewId
        Dim ClassName As String = obj.RunMethod("getClassName", Null).As(String)
        Dim isClickable As Boolean = obj.RunMethod("isClickable", Null).As(Boolean)

        Dim outBounds As JavaObject
        outBounds.InitializeStatic("android.graphics.Rect")
        obj.RunMethod("getBoundsInWindow", Array As Object(outBounds))

        ' and so on with other proprieties....

    Next
End Sub

I don't know very well the use of JavaObject and Reflect, I'm sorry

Anyway, after outBounds.InitializeStatic("android.graphics.Rect") command, outBounds object is not null (I think), here is screenshot

Immagine.png


If I try these two lines, the error is the same: Method: getBoundsInWindow not found in: android.view.accessibility.AccessibilityNodeInfo
B4X:
obj.RunMethod("getBoundsInWindow", Array As Object(Null))

obj.RunMethod("getBoundsInWindow", Null)

Edit:
I changed the inizialize command:
B4X:
outBounds.InitializeNewInstance("android.graphics.Rect", Null)

and I think that is the correct definition, because now outBounds object is
Immagine1.png

but the error is the same: method not found
 
Last edited:
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
solved !!!
here is the code:
B4X:
Dim outBounds As JavaObject
outBounds.InitializeNewInstance("android.graphics.Rect", Null)
obj.RunMethod("getBoundsInScreen", Array As Object(outBounds))
 
Upvote 0
Top