How to extract the contextual information of your android app? which will be used later for the analytics or ads purpose

Basically i want to create an android SDK where it want to get all the information about the host app ‘s content or the current screen’s UI widget like textview, imageview, webview, recyclerview…etc.which is seen by the user.The purpose of this informations is to make ads on basis of the app info.

I’ve already have an idea of doing this with the help of the app’s rootview and traversing its childview for getting its data but is this only way to achieve this? because i don’t think this as an efficient way to proceed.Please let me know the elegant approach

Answer

Such screen info gathering can be achieved by using an Accessibility Service https://developer.android.com/guide/topics/ui/accessibility/service

Accessibility permission requires user consent though as it a dangerous permission.