2

I know there are 4 standard screen sizes for android :

xlarge,large, normal and small 

How to know the running device which screen size has from these 4 sizes ?

Adham
  • 61,516
  • 96
  • 221
  • 343

1 Answers1

20
int screenSize = getResources().getConfiguration().screenLayout &
        Configuration.SCREENLAYOUT_SIZE_MASK;

switch(screenSize) {
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
        Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show();
        break;
    case Configuration.SCREENLAYOUT_SIZE_NORMAL:
        Toast.makeText(this, "Normal screen",Toast.LENGTH_LONG).show();
        break;
    case Configuration.SCREENLAYOUT_SIZE_SMALL:
        Toast.makeText(this, "Small screen",Toast.LENGTH_LONG).show();
        break;
    default:
        Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show();
}
KOTIOS
  • 11,234
  • 3
  • 37
  • 64
  • 3
    Beginning with Android 3.2 (API level 13), these size groups are deprecated in favor of a new technique for managing screen sizes based on the available screen width. If you're developing for Android 3.2 and greater, see Declaring Tablet Layouts for Android 3.2 for more information. http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts – Dmytro Danylyk Jul 12 '13 at 10:30
  • @Monica : I so needed that answer , thanx , +1 for help – Hussain Akhtar Wahid 'Ghouri' Oct 15 '13 at 12:21
  • @HussainAkhtarWahid Welcome – KOTIOS Oct 15 '13 at 12:22
  • @Monica: can we switch of making different layout getting Screen size programetically I am tired of making different layouts for each Devices As we do in Iphone......... – Shani Goriwal Nov 15 '13 at 05:48
  • @ShaniGoriwal yes ,you can get screen resolution programatically – KOTIOS Nov 15 '13 at 06:02
  • @monika thanx for reply... yes we can get screen resolution programatically as u told but m asking can we avoid making different resoulation screen size as large , small and for extra-large... – Shani Goriwal Nov 15 '13 at 06:26