code: static String getUIMode(Context context) {
          String mode = "UI_MODE_TYPE_UNDEFINED";
          UiModeManager modeManager = null;
  
          try {
              if (context != null) {
                  modeManager = (UiModeManager) context.getSystemService(UI_MODE_SERVICE);
              }
  
              if (modeManager != null) {
                  switch (modeManager.getCurrentModeType()) {
                      case 1:
                          mode = "UI_MODE_TYPE_NORMAL";
                          break;
                      case 2:
                          mode = "UI_MODE_TYPE_DESK";
                          break;
                      case 3:
                          mode = "UI_MODE_TYPE_CAR";
                          break;
                      case 4:
                          mode = "UI_MODE_TYPE_TELEVISION";
                          break;
                      case 5:
                          mode = "UI_MODE_TYPE_APPLIANCE";
                          break;
                      case 6:
                          mode = "UI_MODE_TYPE_WATCH";
                          break;
  
                      case 0:
                      default:
                          break;
                  }
              }
          } catch (Exception e) {
              // Have seen reports of "DeadSystemException" from UiModeManager.
          }
          return mode;
      }
docs: Return the current running mode type. May be one of
  {UI_MODE_TYPE_NORMAL Configuration.UI_MODE_TYPE_NORMAL},
  {UI_MODE_TYPE_DESK Configuration.UI_MODE_TYPE_DESK},
  {UI_MODE_TYPE_CAR Configuration.UI_MODE_TYPE_CAR},
  {UI_MODE_TYPE_TELEVISION Configuration.UI_MODE_TYPE_TELEVISION},
  {#UI_MODE_TYPE_APPLIANCE Configuration.UI_MODE_TYPE_APPLIANCE}, or
  {#UI_MODE_TYPE_WATCH Configuration.UI_MODE_TYPE_WATCH}.