Use getSize() , you will get in pixels
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Domanda
I'm trying to get the device's screen resolution and print to screen using the below code, however it's throwing a runtime error when trying to execute it. I think this is happening because the "getHeight" and "getWidth" functions are now "deprecated", but not sure how else to get the devices exact screen resolution
Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
TextView w = (TextView) findViewById(R.id.tWidth);
TextView h = (TextView) findViewById(R.id.tHeight);
w.setText(Integer.toString(display.getWidth()));
h.setText(Integer.toString(display.getHeight()));
Thought this would be a relatively simple task, but seems they've changed it in Android Studio. Any suggestions about how to get the above code working, or a different way of getting the screen resolution?
Edit: Updated Title
Soluzione
Use getSize() , you will get in pixels
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;