How to get screen resolution of your android device..? [duplicate] - android

This question already has answers here:
How to get screen dimensions as pixels in Android
(46 answers)
Closed 9 years ago.
Can i get resolution of android phone..?
if yes then how..?
it will really helpful for me..
Thank you..

If you want the display dimensions in pixels you can use getSize:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
This method was introduced in Android API 13, so if you want to get display metrics for previous APIs use:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int wwidth = 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().
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int width = display.getWidth(); // deprecated
int height = display.getHeight(); // deprecated
Edit: PhoneGap
Use the following to figure out the display size in pixels
function getDeviceDimention() {
console.log("Device Dimention using PhoneGap");
console.log("Width = " + window.innerWidth);
console.log("Height = " + window.innerHeight);
}

For Cordova / Phonegap, I've found that using
var width = screen.width
var height = screen.height
is more reliable than using
var width = window.innerHeight
var 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.

For phonegap you can use this
You can use device-width and device-height
<meta name="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.

You can call
Display display = getWindow().getWindowManager().getDefaultDisplay();
Point outSize = new Point();
display.getRealSize(outSize);
outSize.x is the width and outSize.y is the height. Hope it help.

like this
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
look at this answer Android: How to get screen dimensions

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
Good luck!

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
good luck
행운을 빈다.

u can get screen resolution like this
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height=display.getHeight();

Related

Dynamically change editTexts position based on screen Size / DPI

I would like to change the position of one element (editText) in my UI when the user taps it. The positioning should be ~20 dp under the actionBar, no matter screen-size or DPI the device is using.
How do I accomplish this using only (java)code? Please try to give a more exact answer. I have seen other examples similar to this but none that explains an exakt scenario? I was thinking of a start like the code below? Then what?:
DisplayMetrics dm = new DisplayMetrics();
mSearchField = (EditText)v.findViewById (R.id.something);
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
int [] loc = new int[2];
mSearchField.getLocationOnScreen(loc);
int distance = dm.heightPixels - loc[1];
Get the Display height and width using DisplayMetrics.
DisplayMetrics displayMetrics = new DisplayMetrics();
mContext.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
Log.e("width",width+""+height);

Android Screen size full screen

I need to get the exactly size screen but i cant get it.
I tried this two different codes:
DisplayMetrics display = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
height = display.heightPixels;
width = display.widthPixels;
Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
height = size.y;
width = size.x;
In both cases the height its correct (1080) but the width its not correct. It must return 1920 but its returning 1794. Its a Samsung Galaxy S4 (1920x1080).
I have a full screen app, with no actionbar or navigation bar, etc.
Why is happening this and how can ai get 1920. Im using API >= 14.
Greets
You can try with getRealSize instead of getSize (getRealSize)
Point size = new Point();
getWindowManager().getDefaultDisplay().getRealSize(size);
height = size.y;
width = size.x;

Getting screen size and use in drawbit map

This is not my activity! this is separate class file
i am using Surface view extended to my class file . i wanted to display a small bit map to my canvas my bit map is very small than my phone screen so i used a createscaledbitmap to fit it in my phone screen with this code here
Bitmap o2 = Bitmap.createScaledBitmap( hud, 800, 490, false);
it worked great in my phone but when i tested in a bigger phone i have my bitmap pasted only 3/4 of the screen .. so i want to make my bitmap to fix the phone screen size
Bitmap o2 = Bitmap.createScaledBitmap( hud, phonescreenwidth, phonescreenheight, false);
is there a function to get the phone display size and use in my code ?
like
int phonescreenwidth = surfaceView.getwidth ();
and there is a function called protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
i dont know how to use it . if someone know please tell me how too :)
Thank you all
BY this way you can get width and height of your device and pass it in your method..
WindowManager manager = (WindowManager) getApplicationContext().getSystemService(Activity.WINDOW_SERVICE);
int width, height;
LayoutParams params;
if (Build.VERSION.SDK_INT > VERSION_CODES.FROYO) {
width = manager.getDefaultDisplay().getWidth();
height = manager.getDefaultDisplay().getHeight();
} else {
Point point = new Point();
manager.getDefaultDisplay().getSize(point);
width = point.x;
height = point.y;
}
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
Refer here http://developer.android.com/guide/practices/screens_support.html#testing
and
Get screen dimensions in pixels
try this to get Screen size,,
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
then try passing context from ur baseActivity to the current activity
and then try context.getWindowManger....

How to get screen size? [duplicate]

This question already has answers here:
How to get screen dimensions as pixels in Android
(46 answers)
Closed 8 years ago.
How to get screen size (in pixels)? I used
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;`
but it doesn't work...
use this
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

Emulator does not return actual width and height for 320x240 resolution

I made an application with a dynamic layout for different screen sizes.
It also worked for all screen sizes except of 320x240 screens.
I used the same code to get the width and height for all and it also return the correct value but the it does not return the correct value for manually create emulator means 320x240 and 240x400.
I used the following code:
DisplayMetrics metrics = new DisplayMetrics();
WindowManager manager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
manager.getDefaultDisplay().getMetrics(metrics);
int width=metrics.widthPixels;
int height=metrics.heightPixels;
I am late..but would like to share :)
Please try below code snippets:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

Categories

Resources