¿Hay alguna forma de detectar que la app este corriendo en Tablet
o en Smartphone
?
Hasta ahora lo hago detectando el ancho de pixeles
, pero me encuentro la gama Samsung Galaxy S3, S4... que tienen más resolución que una tablet y no es optimo.
Stack Overflow en español es un sitio de preguntas y respuestas para programadores y profesionales de la informática. Solo te toma un minuto registrarte.
Regístrate para unirte a esta comunidadOlvidate de detectar el ancho de pixeles o la densidad, este método es el que uso y es el sugerido por google:
public static boolean esTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
Adicional info: http://developer.android.com/reference/android/content/res/Configuration.html#screenLayout
public void deterScreenSize() {
if((getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show();
}else if ((getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
Toast.makeText(this, "Normal sized screen" , Toast.LENGTH_LONG).show();
}else if ((getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
Toast.makeText(this, "Small sized screen" , Toast.LENGTH_LONG).show();
}else if ((getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
Toast.makeText(this, "XLarge sized screen" , Toast.LENGTH_LONG).show();
}else {
Toast.makeText(this, "El tamaño de la pantalla no es ni X grande, ni grande, ni normal o pequeña" , Toast.LENGTH_LONG).show();
}
}