Check if screen is in MultiWindowMode without activity

Issue

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()){
        // ...
    }
}

Answered By – GMG

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published