How To Get Screen Resolution Of Your Android Device..?
Solution 1:
If you want the display dimensions in pixels you can use getSize:
Displaydisplay= getWindowManager().getDefaultDisplay();
Pointsize=newPoint();
display.getSize(size);
intwidth= size.x;
intheight= size.y;
This method was introduced in Android API 13, so if you want to get display metrics for previous APIs use:
DisplayMetricsdisplaymetrics=newDisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
intheight= displaymetrics.heightPixels;
intwwidth= displaymetrics.widthPixels;
If you're not in an Activity, you can get the default Display via WINDOW_SERVICE
. Also be sure to set your minSdkVersion to at least 4 in AndroidManifest.xml to enable calls to display.getWidth().
WindowManagerwm= (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
Displaydisplay= wm.getDefaultDisplay();
intwidth= display.getWidth(); // deprecatedintheight= display.getHeight(); // deprecated
Edit: PhoneGap
Use the following to figure out the display size in pixels
functiongetDeviceDimention() {
console.log("Device Dimention using PhoneGap");
console.log("Width = " + window.innerWidth);
console.log("Height = " + window.innerHeight);
}
Solution 2:
For Cordova / Phonegap, I've found that using
var width = screen.width
var height = screen.height
is more reliable than using
var width = window.innerHeightvar height = window.innerWidth
in order to obtain the resolution of the current display. The latter is unfortunately inaccurate if your mark-up either overflows or does not take up all of the space available on the screen.
Solution 3:
For phonegap you can use this
You can use device-width and device-height
<metaname="viewport"content="width=device-width; user-scalable=no" />
You can even get device height and width using jquery & jquery mobile like this
var width = $(window).width();
var height = $(window).height();
NOTE:- Do this when device is ready.
Solution 4:
You can call
Displaydisplay= getWindow().getWindowManager().getDefaultDisplay();
PointoutSize=newPoint();
display.getRealSize(outSize);
outSize.x is the width and outSize.y is the height. Hope it help.
Solution 5:
like this
Displaydisplay= getWindowManager().getDefaultDisplay();
intwidth= display.getWidth();
intheight= display.getHeight();
look at this answer Android: How to get screen dimensions
Post a Comment for "How To Get Screen Resolution Of Your Android Device..?"