I am using accessibility service to find a button on screen and click it, but for some reason I am getting the follow error:
java.lang.IllegalStateException: Cannot perform this action on a not sealed instance.
at android.view.accessibility.AccessibilityNodeInfo.enforceSealed(AccessibilityNodeInfo.java:3046)
at android.view.accessibility.AccessibilityNodeInfo.findAccessibilityNodeInfosByText(AccessibilityNodeInfo.java:1529)
at com.myapp.adapters.Adapter_Click$11.run(Adapter_Click.java:1874)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Method.java:-2)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
And the line that it refers to is:
List<AccessibilityNodeInfo> list = source.findAccessibilityNodeInfosByText("Accept".toLowerCase());
And then I use this to click the button:
if (view.performAction(AccessibilityNodeInfo.ACTION_CLICK))
{
Log.e(TAG, "Button clicked");
}
I didn't see any issues with this for the last year until I just recently updated to AndroidX. Is there a way to check if it is a sealed instance before trying to click it? I even tried to wrap it in a try/catch and it still crashes my app.
(It's kind of a pain, but if a node gets ditched most functionality on it breaks horribly -- even refresh()
. It's strange, since as far as I know you're allowed to retain instances as long as you need them.)
You can easily check if one is still valid by checking if getClassName()
returns null -- if it does, drop it like a hot potato! You can't do anything with it anymore -- don't even recycle()
it because something already did that underneath your feet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With