I've been getting device density like this:
val wm = getSystemService(Context.WINDOW_SERVICE) as WindowManager
val display = wm.defaultDisplay
val metrics = DisplayMetrics()
display.getMetrics(metrics)
val density = metrics.densityDpi
Then I based some logic on the value of density
and constants:
DENSITY_XHIGH
DENSITY_XXHIGH
I expected S10 to fall under DENSITY_XXHIGH
but apparently it's density
value is 420 , contrary to S9 which density is 480 .
ImageView
?If you want to know what is used, I suggest to create a "whoami" string and place it in values-xhdpi
and all other *dpi variants.
values-xhdpi/whoami.xml
<resources>
<string name="density_bucket" translatable="false">xhdpi</string>
</resources>
If you use that value, you know what the Android system selects from during runtime.
As this is a nice way for "debugging" your question to a specific device, you can also adopt to this. In my case this value is used to request the right image sizes from an asset backend.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.