Android code all the current app windows.

Source: Internet
Author: User

Android code all the current app windows.

Android-find all windows in all applications programmatically?

Is it possible to enumerate all current app windows programmatically?

Dialog box, for example, all will be opened in a new window, independent of the main activity window. I can find them through Dialog. getWindow, but I don't know how to do this with a built-in component, for example, in the activity menu pop-up.

Is there any way to enumerate all windows associated with my application from the application context, window manager, or something else?

I can see all my application windows in the adb dumpsys window, but I am looking for a way to do this in my application without the need of root.


Android View

Best Answer:

I found a way to reflect WindowManagerGlobal. At least so far he has worked well in android-18 .....

 

private void logRootViews() {    try {        Class wmgClass = Class.forName(android.view.WindowManagerGlobal);        Object wmgInstnace = wmgClass.getMethod(getInstance).invoke(null, (Object[])null);         Method getViewRootNames = wmgClass.getMethod(getViewRootNames);        Method getRootView = wmgClass.getMethod(getRootView, String.class);        String[] rootViewNames = (String[])getViewRootNames.invoke(wmgInstnace, (Object[])null);         for(String viewName : rootViewNames) {            View rootView = (View)getRootView.invoke(wmgInstnace, viewName);            Log.i(TAG, Found root view:  + viewName + :  + rootView);        }    } catch (Exception e) {        e.printStackTrace();    }}

Output:
Found root view: com. example. paintsample/com. example. paintsample. paintSample/android. view. viewRootImpl @ 41deeff0: com. android. internal. policy. impl. phoneWindow $ DecorView {41dcc278 V. E ..... R ....... 0, 0-768,1184}
Found root view: PopupWindow: 42887380/android. view. viewRootImpl @ 42891820: android. widget. popupWindow $ PopupViewContainer {42891450 V. E ............. 0, 0-424,618}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.