A cordova plugin to get the size of the device screen.
cordova plugin add cordova-plugin-screensize
- Android
- iOS
- OSX
- Browser
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.plugins.screensize.get(successCallback, errorCallback);
}
function successCallback(result) {
console.log(result);
}
The plugin returns a JSON object with the screen sizes.
Return values:
width
<Number> − screen width in pixelsheight
<Number> − screen height in pixelsxdpi
<Number> − physical pixels per inch of the screen in the X dimensionydpi
<Number> − physical pixels per inch of the screen in the Y dimensiondiameter
<Number> − screen diameter in inches (rounded to two decimals)
The correct device metrics setting is the manufacturer's responsibility. In a few cases the xdpi
and ydpi
values are wrong and the diameter calculation returns an incorrect number.
Devices with wrong settings (known so far):
- BLU Life XL (model
BLU LIFE XL
, calculated diameter 8.62" vs. real diameter 5.5") - Samsung Galaxy SIII CDMA (model
SPH-L710
, calculated diameter 9.17" vs. real diameter 4.8") - ZTE nubia Z7 Max (model
NX505J
, calculated diameter 13.77" vs. real diameter 5.5")
iOS has no public API for getting the device's PPI.
The plugin returns the rendered pixels of the screen.
Return values:
width
<Number> − rendered pixel widthheight
<Number> − rendered pixel heightscale
<Number> − render scale (1× or 2× or 3×)
Return values:
width
<Number> − screen width in pixelheight
<Number> − screen height in pixelphysicalWidth
<Number> − width of the display in millimetersphysicalHeight
<Number> − height of the display in millimetersdpi
<Number> − physical pixels per inch of the display
The plugin returns the dimensions of the viewport. You can't get the real physical dimensions or the actual DPI of the browser ( see ).
Return values:
width
<Number> − viewport width in pixelsheight
<Number> − viewport height in pixels
cordova-plugin-screensize is licensed under the MIT Open Source license. For more information, see the LICENSE file in this repository.