code: protected static String getOrientation(Context ctx) {
          try {
              String o;
              switch (ctx.getResources().getConfiguration().orientation) {
                  case android.content.res.Configuration.ORIENTATION_LANDSCAPE:
                      o = "landscape";
                      break;
                  case android.content.res.Configuration.ORIENTATION_PORTRAIT:
                      o = "portrait";
                      break;
                  default:
                      o = null;
                      break;
              }
              return o;
          } catch (Exception e) {
              Log.e(TAG, "Error getting device orientation.", e);
              return null;
          }
      }
docs: Get the device's current screen orientation.
  
  @param ctx Android application context
  @return the device's current screen orientation, or null if unknown