Unable to detect dialect using emulator

Hello,
I am using appium studio 12.4.5043 and Emulator(Nexus_5X_API_28_x86:5554) to open One app. But I am not able to open the app when I use an emulator but when I use the same code for real device it opens the app(Note: I have defined the device name properly in capabilities for each of the devices).

Class**********
public class Mobile_Test {
private String reportDirectory = “reports”;
private String reportFormat = “xml”;
private String testName = “Test”;
protected AndroidDriver driver = null;
DesiredCapabilities dc = new DesiredCapabilities();

@BeforeMethod
public void setUp() throws MalformedURLException {
    dc.setCapability("reportDirectory", reportDirectory);
    dc.setCapability("reportFormat", reportFormat);
   // dc.setCapability(MobileCapabilityType.APP,app);
    dc.setCapability("testName", testName);
    dc.setCapability(MobileCapabilityType.UDID, "emulator-5554");
    dc.setCapability("appPackage", "com.test.first");
dc.setCapability("com.test.first.MainActivity");
    driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
    driver.setLogLevel(Level.INFO);
}

@Test
public void tested() {

new WebDriverWait(driver, 120).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//[@text=‘Welcome’ and @class=‘android.web.View’]")));
driver.findElement(By.xpath("//
[@text=‘Welcome’ and @class=‘android.web.View’]")).click();

}

@AfterMethod
public void tearDown() {
    driver.quit();
}

}

Help will be appreciated.

Are you using this code inside Appium Studio or in Eclipse ?

Hello Kishor,
Thanks for the reply, I am using Eclipse for code writing.

Can you check if its works when you run from Appium Studio (Similar code) , I think there is a problem when you run from eclipse … in identifying the Emulator device.

Please check and let me know

Okay Kishor I’ll check and let you know

Please use

dc.setCapability(“deviceQuery”, “(@serialnumber=‘emulator-5554’) and (@emulator=‘true’)”);

instead of

dc.setCapability(MobileCapabilityType.UDID, “emulator-5554”);