Automatic Android Appium capability setup

Is there any way to setup appium device capability automatically once devices are connected instead of writing below code.
Is there a way that java code can set the Device name, platform just by connecting device and running the code.

capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
capabilities.setCapability(CapabilityType.VERSION, “4.2”);
capabilities.setCapability(CapabilityType.PLATFORM, “WINDOW”);