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

2

6

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?

Largish answered 10/3, 2017 at 12:18 Comment(0)
K
5

You must add ViewTreeObserver. And check if device enter in Multi-Window mode

getActivity().isInMultiWindowMode()
Kealey answered 22/5, 2017 at 12:42 Comment(0)
H
1

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{

      }
}
Harleigh answered 2/2, 2018 at 12:33 Comment(3)
Is there a similar API to isInMultiWindowMode, that can be called outside of an Activity ?Compete
In case of fragment you can access by getActivity().isInMultiWindowMode() else access by passing context to non activity classHarleigh
A fragment is inside an Activity. When it's not attached to Activity, it can't use it... I asked about outside of an Activity...Compete

© 2022 - 2024 — McMap. All rights reserved.