Android: Disable application for tablet

This prevents access on tablets, but allows the new density buckets (xxhdpi and xxxhdpi) and avoids errors on projects that are compiled against lower SDKs. It should be a direct child of the <manifest> element in AndroidManifest.xml <compatible-screens> <!– all small size screens –> <screen android:screenSize=”small” android:screenDensity=”ldpi” /> <screen android:screenSize=”small” android:screenDensity=”mdpi” /> <screen android:screenSize=”small” android:screenDensity=”hdpi” … Read more

Android DisplayMetrics returns incorrect screen size in pixels on ICS

From the answer of Ahmed, this is full code without error: int width = 0, height = 0; final DisplayMetrics metrics = new DisplayMetrics(); Display display = getWindowManager().getDefaultDisplay(); Method mGetRawH = null, mGetRawW = null; try { // For JellyBean 4.2 (API 17) and onward if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealMetrics(metrics); width = metrics.widthPixels; height … Read more

Supporting multiple screen size – Android

I just did something very similar. To stretch the app without creating new layouts I used dimensions set in XML res/values/dimensions.xml res/values-sw600dp/dimensions.xml -> 7+ inches res/values-sw720dp/dimensions.xml -> 10+ inches Dimensions are resources files: <dimen name=”default_padding”>11dp</dimen> You can increase the dimensions by about 30% in the 600 and 720 file. Then simply used @dimen/default_padding in your … Read more

How to get android device screen size?

try this code to get screen size in inch DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int width=dm.widthPixels; int height=dm.heightPixels; double wi=(double)width/(double)dm.xdpi; double hi=(double)height/(double)dm.ydpi; double x = Math.pow(wi,2); double y = Math.pow(hi,2); double screenInches = Math.sqrt(x+y);

Setting drawable folder to use for different resolutions

How do I force the Nexus to use resources in drawable-xhdpi and then the 10 inch tab to use drawable-xxhdpi? You can’t. The qualifiers hdpi,xhdpi,xxhdpi describes the screen density of the device, not the size of screen. From the official doc Screen density The quantity of pixels within a physical area of the screen; usually … Read more

How do I get the ScreenSize programmatically in android

Copy and paste this code into your Activity and when it is executed it will Toast the device’s screen size category. int screenSize = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; String toastMsg; switch(screenSize) { case Configuration.SCREENLAYOUT_SIZE_LARGE: toastMsg = “Large screen”; break; case Configuration.SCREENLAYOUT_SIZE_NORMAL: toastMsg = “Normal screen”; break; case Configuration.SCREENLAYOUT_SIZE_SMALL: toastMsg = “Small screen”; break; default: toastMsg = … Read more