Android lists all the windows in the current app in a coded way

Source: Internet
Author: User

Android-Programmatically find all the windows in all applications?

Is it possible to programmatically enumerate the windows of all current apps

dialog boxes, for example, will open in a new window, independent of the main activity window. I can go through Dialog.getwindow (Find them), but I don't know how I can do this with a built-in component, such as popping up in the active menu.

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

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


Android's Android View

Best Answer:

I found a way to windowmanagerglobal through reflection, at least so far he has worked very well in the android-18 version .....


[Java] view plaincopy650) this.width=650; "src=" Https://code.csdn.net/assets/CODE_ico.png "width=" 12 " Height= "alt=" on code to view the chip "style=" Border:none; "/>650" this.width=650; "src=" Https://code.csdn.net/assets/ico _fork.svg "width=" height= "alt=" derived from My Code slice "style=" border:none; "/>

  1. Private void logrootviews () {

  2. Try  {  

  3.          class wmgclass = class.forname ( "Android.view.WindowManagerGlobal"

  4.          object wmginstnace = wmgclass.getmethod ( "getinstance" null null

  5. Method getviewrootnames = Wmgclass.getmethod ("Getviewrootnames");

  6.          method getrootview = wmgclass.getmethod ( "Getrootview" , String. class

  7. String[] Rootviewnames = (string[]) Getviewrootnames.invoke (Wmginstnace, (object[])null);

  8. for (String viewname:rootviewnames) {

  9. View Rootview = (view) getrootview.invoke (Wmginstnace, viewName);

  10. LOG.I (TAG, "Found root view:" + viewName + ":" + Rootview);

  11. }

  12. } catch (Exception e) {

  13. E.printstacktrace ();

  14. }

  15. }


Output:
Found root view:com.example.paintsample/com.example.paintsample.paintsample/[email protected]: com.android.internal.policy.impl.phonewindow$decorview{41dcc278 v.e ..... R....... 0,0-768,1184}
Found root View:popupwindow:42887380/[email protected]: android.widget.popupwindow$popupviewcontainer{42891450 V.e ........ 0,0-424,618}


This address: http://www.itmmd.com/201412/297.html


Android lists all the windows in the current app in a coded way

Related Article

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.