1

I am trying to implement Picture in Picture mode but so far as per the example given the only orientation I see is landscape mode.

https://developer.android.com/guide/topics/ui/picture-in-picture

I am trying to have a functionally similar to the WhatsApp app. When the user accepts a call and enters picture in picture mode the window is shown in portrait mode so the user can see the other person well. Will appreciate thoughts on how I can implement this.

override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean,
                                           newConfig: Configuration) {
    if (isInPictureInPictureMode) {
        // Hide the full-screen UI (controls, etc.) while in picture-in-picture mode.
    } else {
        // Restore the full-screen UI.
    }
}
Matt Ke
  • 3,599
  • 12
  • 30
  • 49
Maria
  • 377
  • 2
  • 15

1 Answers1

2

You can use enterPictureInPictureMode to configure the PIP window.

To have a portrait PIP window use an aspect ratio of ~2/3. (The aspect ratio must be between 0,42 and 2,39.)

override fun onUserLeaveHint() {
    enterPictureInPictureMode(PictureInPictureParams.Builder()
            .setAspectRatio(Rational(2, 3))
            .build())
}

Example:

pip-example

Matt Ke
  • 3,599
  • 12
  • 30
  • 49