Skip to content

Instantly share code, notes, and snippets.

@MarioPerezEsteso
Created April 12, 2015 14:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarioPerezEsteso/a30f8de03a6171fc0b59 to your computer and use it in GitHub Desktop.
Save MarioPerezEsteso/a30f8de03a6171fc0b59 to your computer and use it in GitHub Desktop.
Obtener información de la pantalla en Android
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