Emulated Android device: How to get scale / pixel ratio to match physical phone with non-standard density?

Viewed 76

My emulated android device has a scale value (MediaQuery.devicePixelRatio in flutter) that is different from the one of my physical device (Samsung Galaxy S21 Ultra), so all sizes are different on the emulated device (3.0x) than on my physical device (3.5x). I have made sure that the device size and screen resolution is set correctly in the emulator. I guess the problem is that the pixel ratio of 3.5x doesn't fall into the "official" density buckets (xxhdpi has 3.0x, xxxhdpi has 4.0x).

How can I change the devicePixelRatio in the emulator, so it correctly reflects how things will look on my real phone? And why does it deviate in the first place?

1 Answers

yes, It is very much possible... you will need to change config.ini file in PATH:

.android/avd/<device_name>.avd/config.ini

you have to change the following properties:

hw.height, hw.width and hw.density

density is dpi. so either you can change density to that of device or more stable

option is to change hw.height and hw.width, with values calculated using:

find

DPR: original_ppi/ 150 (standard ppi)

find viewport = Original Resolution/DPR

emulator_DPR = mention DPR(hw.density)/150

now hw.height x hw.widht = viewport * emulator_DPR

Related