Inside an Android app, I tried using the following way to obtain the screen width and height:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
final int screenWidth = metrics.widthPixels;
final int screenHeight = metrics.heightPixels;
This reports 1080 and 1920 respectively for my phone, which matches the specs.
However, inside a webview, when I used:
var screenWidth = $(window).width();
This reports only 360.
From this what I understand, both are using pixel as unit, so why are the values different?
Notice width is same in both cases but units are different.
E.g.
This is in Pixels metrics.widthPixels;
This one is in Dps 360 OR $(window).width();
Convert 360Dps to pixels
On xxhdpi device, 360dps = 1080px
Dp to pixels & vice versa
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With