Home » Android » Programmatically enter multi-window mode in Android N

Programmatically enter multi-window mode in Android N

Posted by: admin June 15, 2020 Leave a comment

Questions:

Android N has a new feature – Multi Window Mode. It enables two applications to be active side-by-side (actually one one is active, other one is paused but we can see both simultaneously).

I am looking for an API that I can call to have my application enter multi-window mode. I couldn’t find much help in Android N SDK docs. I am trying to have two activities of my app run side by side, but without user having to do manual steps.

MANUALLY ENTERING MUTLI-WINDOW MODE
The user can switch into multi-window mode in the following ways:

If the user opens the Overview screen and performs a long press on an activity title, they can drag that activity to a highlighted portion of the screen to put the activity in multi-window mode.
If the user performs a long press on the Overview button, the device puts the current activity in multi-window mode, and opens the Overview screen to let the user choose another activity to share the screen.

How to&Answers:

The SDK for API 24 introduced a new constant to toggle split screen mode from an accessibility service:
https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html#GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN

The constant can be passed to following method:
https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html#performGlobalAction(int)

Google seems to have missed to document the new constant in the performGlobalAction method. I still consider this to be an official API since Google did not mark the constant as hidden.

You have to implement an accessibility service in your app and let the user manually enable the service in system settings->Accessibility so it might not be a viable option for all apps.

Answer:

As of Android N, this is not supported.

The only supported way to enter multi-window mode is if the user manually triggers it.

Answer:

I don’t think that an api for the thing you want to do exists, You could try making your app have two fragments on each side of the screen. With a black bar in the middle, make each fragment resize according to the “X” position of the bar. 🙂