Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting list of all Windows in Android

Tags:

android

Is it possible to get a list of all Windows in my Android app?

If not, is it possible to get notifications on creation of a new View or a Window?

Cheers :)

For example: I would like to know if there's a visible keyboard view on the screen, or if there's an alert dialog on screen. Is that possible? Can I get the View or Window instance holding it?

like image 748
gilm Avatar asked Aug 29 '12 13:08

gilm


People also ask

How can I see all windows on Android?

If you have a newer Android phone, swipe up from the bottom-right corner of the screen. If your phone has physical navigation buttons, press the square app switcher button next to the home button. There may also be an icon with three vertical lines to access the app switcher.

How do I get all apps on Android?

Find & open appsSwipe up from the bottom of your screen to the top. If you get All Apps , tap it. Tap the app that you want to open.

How do I list all Android apps installed on device programmatically?

You can Find the List of installed apps in Android Device by using below code, "packageInfo" Contains Installed Application Information in Device. we can retrive Intent for the application installed from the packageinfo object and by using startactivity(intent), can start application.

What is WindowManager in Android?

The Android WindowManager is a system service, which is responsible for managing the z-ordered list of windows, which windows are visible, and how they are laid out on screen. Among other things, it automatically performs window transitions and animations when opening or closing an app or rotating the screen.


1 Answers

Yes this is possible in a number of different ways. All views being displayed on the screen are added to a ViewGroup, which are usually layouts such as R.layout.main, LinearLayout, RelativeLayout, etc.

You can access the views at runtime, after the layouts have been built, using a handler such as onWindowFocusChanged:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    int count = myLayout.getChildCount();
    for(int i = 0; i < count; i++)
    {
    View v = myLayout.getChildAt(i);
    ...
    }
}

You can simply set up a thread inside onWindowFocusChanged that would notify you if a keyboard is created by constantly checking the number of children views of the current layout.

like image 176
Wait what Avatar answered Sep 23 '22 11:09

Wait what