Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when device goes to multi-window mode of Android N

I want to get notified from my background service when the user switches to multi-window mode. Is there a way to get this information by a service other than the activities involved in the process.

Also I have noticed that when an overlay is clicked on the area of the foreground window it automatically switches to the activity under the area. Can this be prevented?

like image 891
dastha2002 Avatar asked Mar 10 '17 12:03

dastha2002


2 Answers

You must add ViewTreeObserver. And check if device enter in Multi-Window mode getActivity().isInMultiWindowMode()

like image 200
Geralt_rivv Avatar answered Oct 08 '22 13:10

Geralt_rivv


isInMultiWindowMode() is added in API 24 to check device is in Multi window or not, it returns a boolean value. when ever device goes to Multi window it triggers onConfigurationChanged() method. There you can handle Landscape and portrait mode.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
     if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
      {
        //do something
      }else{

      }
}
like image 33
anand krish Avatar answered Oct 08 '22 14:10

anand krish