I have an app that uses Exoplayer to play VideoStreams that works and looks good as long as I set the app to develop with buildvariant. But when I build the app for publishing, the coordinator layout that is the top layout of the app and is in activity_main.xml has an X value of 41 dp. In investigating this issue, I found that the WindowManager getCurrentWindowMetrics().getBounds() has a value of Rect(124, 0 - 2997, 1440). So bounds.left = 124 ! The emulator window I am using is set to 1440 x 3120. The bug was originally found on a Pixel 7.
In debug mode, the bars on the left and right sides are black, so Exoplayer can display its content in 16:9 without cropping. The same is true in Release mode, but since the above bug occurs, the left and right sides are gray and cannot be changed because my app can only draw within the window borders.
In portrait mode everything is fine and all borders are set to 0. The orientation of the view is changed by calling
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
android:configChanges
are not set and onconfigchanges is not handled by the Activity, but when I try it, it makes no difference as bount.left is still set to 124.
I also noticed that if I start the app in landscape mode, the app starts with bounds.left = 124 but is then recreated by onconfigchanges with bounds.left = 0. However, this does not happen when opening the fragment that should be displayed in landscape mode. (by fullscreenbutton click setting activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE )
I would like to have an app that uses the correct bounds from the start, but also setting the system background to black so my app displays correctly would be fine to start with.
I tried catching onconfigchanges, find out a way to recalculate the bounds with no luck.