It is common knowledge that we can observe or query the view hierarchy of any app with an AccessibilityService
:
Create your own accessibility service
.
It is also possible to perform actions on behalf of the user:
Developing an Accessibility Service for Android
.
My question is, can we modify the view hierarchy of a foreground app with an AccessibilityService
?
I have already referred the following questions:
What they're doing is using the WindowManager
and the SYSTEM_ALERT_WINDOW
permission to overlay a view on top of the app in the foreground. The problem with this approach is that if the user presses BACK or HOME, the app is dismissed, but the view remains visible on the screen, even after the app is gone. The view is on TOP of the view hierarchy, and not a part of it.
- Is there a way to add / modify the
AccessibilityNodeInfo
objects? - Are these the same as a
View
orViewGroup
? - Are we allowed to add views or modify existing views with an
AccessibilityService
?
My requirement is to display a small view within the app itself. It has to be part of the view hierarchy of the app, so that it stays or goes with the app. For this I need to modify the view hierarchy of the app, namely the
AccessibilityNodeInfo
objects retrieved from the service.
What I want is something similar to addView()
, but add the View
to the view hierarchy of the app itself, not on top of it.
How can we do this? Is this possible?
UPDATE: