3

Is it possible for an Activity to get to and inspect, ideally even modify, the entire View hierarchy for itself, without knowing IDs of all the views or special access such as instrumentation mode or rooting?

E.g. would it be possible to write some code that locates all, say, EditText instances in the Activity's View hierarchy and does something to them?

Thanks

Cumbayah
  • 4,415
  • 1
  • 25
  • 32

1 Answers1

1

Is it possible for an Activity to get to and inspect, ideally even modify, the entire View hierarchy for itself, without special access such as instrumentation mode or rooting?

findViewById(android.R.id.content) returns the View that hosts the content you supplied in setContentView(). Beyond that, try getRootView() (called on any View) to retrieve "the topmost view in the current view hierarchy".

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • That would seem a good approach to get me the anchor point, and then recursively traverse ViewGroups down through the hierarchy. Thanks for your input. – Cumbayah Apr 07 '13 at 19:21
  • Sir, are you aware how is it possible to get the view hierarchy of another app within my app? It's possible, see [Developer Assistant](https://play.google.com/store/apps/details?id=com.appsisle.developerassistant). – azizbekian Apr 03 '19 at 14:00
  • @azizbekian: "It's possible" -- not really. That app presumably is abusing accessibility APIs, or perhaps autofill APIs. Neither of those give you the `View` hierarchy of another app. – CommonsWare Apr 03 '19 at 14:06