How to open new app while another app test case is already running

How do I open messaging app when test case is running for any other app.

Need to fetch OTP from messaging app during a test case is running for my android app. I have tried to create new instance RemoteWebDriver for Appium server with messaging app capabilities.
//Open messaging app to fetch OTP.
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(“appPackage”, “com.android.mms”);
cap.setCapability(“appActivity”, “com.android.mms.ui.ConversationList”);
driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub”), cap);

But, above code is not working and got error -

A new session could not be created. (Original error: Requested a new session but one was in progress)
I am using testNG, Appium, Eclipse on Windows7.

Why you need a new driver. The OTP is on same device, so you can use active driver.

In couple hours I’ll try to post a piece of code to read OTP since so many people is asking about it.

Thank you for pointing out the issue. Any help will be greatly appreciated. :slight_smile:

Check this and see if it helps you.