Random
Manage Appium Capabilities Dynamically
DeviceInfo deviceInfo = new DeviceInfoImpl(DeviceType.ALL);
Device device = deviceInfo.getFirstDevice();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PLATFORM, device.getDeviceProductName());
capabilities.setCapability("platformName", device.getDeviceProductName());
capabilities.setCapability(CapabilityType.VERSION, device.getProductVersion());
capabilities.setCapability("deviceName", device.getModelNumber());
capabilities.setCapability("udid", device.getUniqueDeviceID());
capabilities.setCapability("app", "#Your App File#");
driver = new RemoteWebDriver(new URL(URL), capabilities);
https://github.com/Testinium/MobileDeviceInfo