Programmatically enter multi-window mode in Android N

為{幸葍}努か 提交于 2019-12-21 10:19:09

问题


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.


回答1:


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.




回答2:


As of Android N, this is not supported.

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




回答3:


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. :)



来源:https://stackoverflow.com/questions/36567799/programmatically-enter-multi-window-mode-in-android-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!