Created
April 12, 2015 14:35
-
-
Save MarioPerezEsteso/a30f8de03a6171fc0b59 to your computer and use it in GitHub Desktop.
Obtener información de la pantalla en Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Display display = getWindowManager().getDefaultDisplay(); | |
String displayName = display.getName(); // minSdkVersion=17+ | |
Log.i(TAG, "Pantalla = " + displayName); | |
// Tamaño en píxeles | |
Point size = new Point(); | |
display.getSize(size); | |
int width = size.x; | |
int height = size.y; | |
Log.i(TAG, "Ancho = " + width); | |
Log.i(TAG, "Alto = " + height); | |
// dpi | |
DisplayMetrics metrics = new DisplayMetrics(); | |
getWindowManager().getDefaultDisplay().getMetrics(metrics); | |
int heightPixels = metrics.heightPixels; | |
int widthPixels = metrics.widthPixels; | |
int densityDpi = metrics.densityDpi; | |
float xdpi = metrics.xdpi; | |
float ydpi = metrics.ydpi; | |
Log.i(TAG, "Ancho en píxeles = " + widthPixels); | |
Log.i(TAG, "Alto en píxeles = " + heightPixels); | |
Log.i(TAG, "Densidad dpi = " + densityDpi); | |
Log.i(TAG, "x dpi = " + xdpi); | |
Log.i(TAG, "y dpi = " + ydpi); | |
// Deprecated | |
int screenHeight = display.getHeight(); | |
int screenWidth = display.getWidth(); | |
Log.i(TAG, "Alto de pantalla = " + screenHeight); | |
Log.i(TAG, "Ancho de pantalla = " + screenWidth); | |
// Orientación | |
int orientation = getResources().getConfiguration().orientation; | |
Log.i(TAG, "Orientación = " + orientation); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment