I configured a secondary display for my android device. By default, the secondary display will mirror the content of the main diaplsy.
Then I use DisplayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION)
to get secondary displayId
and use ActivityOptions
to start an Activity
on secondary display, then it changes from mirror mode to show my Activity
page.
Now I have a need to switch secondary display back to mirror mode without finish Activity
, but I can't find any API
to switch back to mirror mode.
So is there any way to flexibly switch the display mode of the secondary display?
My start Activity
on secondary display code like this:
val displays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION)
val secondaryDisplay = displays.firstOrNull()
if (secondaryDisplay != null) {
val displayId = secondaryDisplay.displayId
val context = activity.createDisplayContext(secondaryDisplay)
val intent = Intent(context, activityClazz)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (isActivityStartAllowedOnDisplay(context, displayId, intent)) {
val ops = ActivityOptions.makeBasic().apply { launchDisplayId = displayId }
context.startActivity(intent, ops.toBundle())
} else {
Log.e(TAG, "Cannot start activity to secondary display: $displayId")
}
}