androidandroid-7.0-nougatsplit-screen

Check if screen is in MultiWindowMode without activity


Is there any way to find out if screen is split if I have no access to Activity? (Structurally I can't call isInMultiWindowMode method.

I see that default Activity#isInMultiWindowMode() implementation is:

public boolean isInMultiWindowMode() {
    try {
        return ActivityManagerNative.getDefault().isInMultiWindowMode(mToken);
    } catch (RemoteException e) {
    }
    return false;
}

Is there any workaround ?


Solution

  • Inside Fragment you can use

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (((Activity)getContext()).isInMultiWindowMode()){
            // ...
        }
    }