'Screen recorder app not detecting my screen size (width and height)
Source: here
With the following segment of code all my Android devices record with a maximum width of 960 rather than the device width.
val metrics = resources.displayMetrics
val rawWidth = metrics.widthPixels
val rawHeight = metrics.heightPixels
val scale = if(maxOf(rawWidth, rawHeight) > 960){
960f / maxOf(rawWidth, rawHeight)
} else 1f
val width = (rawWidth * scale).roundToInt()
val height = (rawHeight * scale).roundToInt()
My phone has a 1080x2400 screen and above code just records video with resolution 432x960. In order to fix it, I modified the code as it follows hoping that now it would record with my device resolution:
val metrics = resources.displayMetrics
val rawWidth = metrics.widthPixels
val rawHeight = metrics.heightPixels
val scale = 1f
val width = (rawWidth * scale).roundToInt()
val height = (rawHeight * scale).roundToInt()
However that causes the app to not record anything at all.
I know I could type manually something like val 'width = 1080' and 'val height = 1920' but then I would have to create an app version for each one of my android devices, that's why I'd like the app to be able to find out the right number for each device running the app
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|