android 以編碼的方式列出來當前app所有的視窗

來源:互聯網
上載者:User

android 以編碼的方式列出來當前app所有的視窗

Android的 - 以編程方式找到所有應用程式中所有的的視窗?

是否有可能以編程方式枚舉所有當前app的視窗

對話方塊,例如都將在新視窗中開啟,獨立於主activity視窗。我可以通過Dialog.getWindow(找到它們),但我不知道我怎麼會用一個內建的組件做到這一點,如在活動菜單彈出。

有沒有什麼辦法,從應用程式中,上下文,或者視窗管理器,還是其他什麼東西,枚舉與我的應用程式關聯的所有視窗?

我可以在adb dumpsys視窗看到我所有的應用程式的視窗,但我正在尋找一種方法來在我的應用程式做到這一點,無需root。


Android的Android的視圖

最佳答案:

我找到一個方法通過反射 WindowManagerGlobal.,至少到目前為止他在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();    }}

輸出:
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}

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.