I know there are a lot of questions similar to my title but I couldn't find the answer that I want.
In my app, I am using window.innerWidth
and window.innerHeight
to get the screen size, but these two values return different size. For example when I run my app on Note 3, I get 360x615 while it should be 1080x1920.
The following code in Java gives me what I want:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
So is there any way in Phonegap to get the same screen size value as Java?
Update: when I test the same code on Note 2 with Jelly Beans I get the correct size 720x1230
Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.
I am using this code hope it help you
var physicalScreenWidth = window.screen.width * window.devicePixelRatio;
var physicalScreenHeight = window.screen.height * window.devicePixelRatio;
I am assuming you want to figure out the actual device pixels instead of the more commonly measured CSS pizels? You could read up on this here.
Basically, if you want to know actual device pixels you could use screen.width
and screen.height
. If you want to know CSS pixels you could use window.innerWidth
and window.innerHeight
.
The meta viewport tag may be ignored on certain Android devices, those are my experiences with Samsung Galaxy tab devices anyway.
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