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 ?
I think the only way to do this without an Activity
is by using an AccessibilityService
that has the permissions to get the list of windows currently displayed and check if there's a window whose type is AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER
.
For example, you could have the following method to do so:
private boolean inSplitScreenMode(List<AccessibilityWindowInfo> windows) {
for (AccessibilityWindowInfo window : windows) {
if (window.getType() == AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER) {
return true;
}
}
return false;
}
check this method when receiving window state changed accessibility events
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if ((event.getEventType() & AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) != 0) {
if (inSplitScreenMode(getWindows()) {
Log.d(TAG, "Split screen mode detected");
} else {
Log.d(TAG, "No split screen");
}
}
}
Inside Fragment you can use
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (((Activity)getContext()).isInMultiWindowMode()){
// ...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With