Code to find the Device is Tablet or Small Device,Android

public


boolean isTabletDevice(Context activityContext) {
// Verifies if the Generalized Size of the device is XLARGE to be

// considered a Tablet

boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout &

Configuration.
SCREENLAYOUT_SIZE_MASK) ==

Configuration.
SCREENLAYOUT_SIZE_XLARGE);

boolean large = ((activityContext.getResources().getConfiguration().screenLayout &

Configuration.
SCREENLAYOUT_SIZE_MASK) ==

Configuration.
SCREENLAYOUT_SIZE_LARGE);




// If XLarge, checks if the Generalized Density is at least MDPI

// (160dpi)

if (xlarge) {

DisplayMetrics metrics =
new DisplayMetrics();

Activity activity = (Activity) activityContext;

activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);


// MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,

// DENSITY_TV=213, DENSITY_XHIGH=320

/* if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT

|| metrics.densityDpi == DisplayMetrics.DENSITY_HIGH

|| metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM

//|| metrics.densityDpi == DisplayMetrics.DENSITY_TV

|| metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { */



// Yes, this is a tablet!

return true;

//}

}

else if (large) {

DisplayMetrics metrics1 =
new DisplayMetrics();

Activity activity1 = (Activity) activityContext;

activity1.getWindowManager().getDefaultDisplay().getMetrics(metrics1);


Log.d(
"is tablet","large???"+large);


// MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,

// DENSITY_TV=213, DENSITY_XHIGH=320

/* if (metrics1.densityDpi == DisplayMetrics.DENSITY_DEFAULT

|| metrics1.densityDpi == DisplayMetrics.DENSITY_HIGH

|| metrics1.densityDpi == DisplayMetrics.DENSITY_MEDIUM

//|| metrics.densityDpi == DisplayMetrics.DENSITY_TV

|| metrics1.densityDpi == DisplayMetrics.DENSITY_XHIGH) {

*/


Log.d(
"is tablet","if large called.???"+large);


// Yes, this is a tablet!

return true;


// }

}


// No, this is not a tablet!

return false;

}

Comments

Popular posts from this blog

Custom Dialog with no title and full screen in Android

Best working code to set Date limits on Date Picker Dialog,in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard