How do I get the ScreenSize programmatically in android

Determine Screen Size :

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();

 }

Determine density:

int density= getResources().getDisplayMetrics().densityDpi;
   switch(density)
  {
  case DisplayMetrics.DENSITY_LOW:
     Toast.makeText(context, "LDPI", Toast.LENGTH_SHORT).show();
      break;
  case DisplayMetrics.DENSITY_MEDIUM:
       Toast.makeText(context, "MDPI", Toast.LENGTH_SHORT).show();
      break;
  case DisplayMetrics.DENSITY_HIGH:
      Toast.makeText(context, "HDPI", Toast.LENGTH_SHORT).show();
      break;
  case DisplayMetrics.DENSITY_XHIGH:
       Toast.makeText(context, "XHDPI", Toast.LENGTH_SHORT).show();
      break;
  }

for Ref: http://devl-android.blogspot.in/2013/10/wifi-connectivity-and-hotspot-in-android.html


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 = "Screen size is neither large, normal or small";
}
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();

private static String getScreenResolution(Context context)
{
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;

    return "{" + width + "," + height + "}";
}