Is there a way to programmatically locate all Windows within a given application?

后端 未结 5 1081
孤街浪徒
孤街浪徒 2020-12-02 17:51

Is it possible to programmatically enumerate all of the android.view.Windows, or decor views within an application?

Dialogs for example wil

5条回答
  •  天命终不由人
    2020-12-02 18:01

    Every solution is in Java above and I made the solution for Kotlin converting the Andrew Lavers's answer-

    try
        {
            val wmgClass = Class.forName("android.view.WindowManagerGlobal")
            val wagInstance = wmgClass.getMethod("getInstance").invoke(null)
            val getViewRootNames: Method = wmgClass.getMethod("getViewRootNames")
            val getRootView: Method = wmgClass.getMethod("getRootView", String::class.java)
            val rootViewNames = getViewRootNames.invoke(wagInstance) as Array
            for (viewName in rootViewNames) {
                val rootView = getRootView.invoke(wagInstance, viewName) as View
    
            }
        } catch (exception: java.lang.Exception {}
    

提交回复
热议问题