Search code examples
javascriptcordovascreensamsung-mobile

cordova misreporting screen.width and screen.height


I have this code in the beginning of my cordova android app

document.addEventListener("deviceready", onDeviceReady, false);    
function onDeviceReady() {    
   alert("screen width is " + screen.width + " screen height is " + screen.height);
}

but it is not working as intended:

Galaxy Note 3 is total garbage: (should report 1920×1080) enter image description here

Hisense HS-U980 works fine (should report 1280x720)

enter image description here

It worked with the genymotion emulator, and I have no reason to doubt it would stop working now, this is as far as testing with actual mobile devices went - I am not going further dragging a plethora of handsets into the office from all over until I know why. Ideas would be appreciated


Solution

  • I have a same problem two solutions :

    • you need hard write on you viewport your height and your width.

    • or you need dynamics rewrite view port with JavaScript. You need use DPI device * screen.height and than width.