[How to] Read SMS from native messaging app (p.e. to read OTP)


There as been couple request to read SMS received, mainly SMS containing some kind of verification code (OTP). This is my attempt to do so in a more standard way (without having to write code for each native messaging app).

For Android

  • I picked one random SMS Popup App from play store and extracted the apk. You can access it in here: SMSPopup.apk

  • I implemented a class where you can install the SMS reader app, enabled it, read SMS and uninstall it. The class is available in here: ExtractCode.java

  • I did not spent time checking if SMSPopup was already installed or not, so I uninstalled it every time, so that the enable process works without problems. But I left the instructions in comments on how to do it, if you want to spent time doing it.

  • The way I called the methods in the small example I did was:

      AppiumDriver driver = Drivers.getDriver(device);
      ExtractCode eCode = new ExtractCode(driver);
      String mySMS = eCode.returnSMS();

For iOS

I don’t have any MAC in here or have tried this in a long time, so I’ll just post how I did it, when I needed it.

  1. In iPhone go to Settings
  2. Go to Notifications
  3. Tap on Messages
  4. Select Alerts on Alert style when unlocked section
  5. Make sure options Show Previews is enabled

SMS will be received in a dialog like it appears in the image below, and you should be able to read the SMS and close the dialog before proceeding your tests (attention: any received SMS will trigger this dialog, so take than into account on your tests).

Hope any of this can help someone.


Is it workable for IOS or only Android

You have an alternative for Android and other for Android, read post :slight_smile:

1 Like

http://www.droidbin.com/p1ajnc11sp13o3gd21cdi1un3dlh3 link return 404 :sweat:

link is also broken with 404 “An error has been encountered in accessing this page.” :frowning:

Thanks @KatzBo for letting me know.

I’m not 100% sure of my original code :slight_smile: but I re-uploaded the code and APK on new links

are the links useable?
I read alot of your replys about the OTP sms test …
Can you suggest me what is the best way to check an OTP sms msgs?

I am testing Android with Java using Eclipse …

Follow tutorial and yes, links are usable now

1 Like

could you kindly upload SMSPopup.apk to a free download site? for apkshared site have to be signup with your credit card information, could you upload the APK file to for example google drive?


changed the link. Please be aware that I have no rights over that app and it is just a random app that I downloaded from the store.

Thanks for the hint

thanks for your work, and note the right of the app, I think all guys of Appium just use it in test only purpose.

“SMS ON IOS” does not seems to work anymore.
Appium ver: 1.6.4 (appium desktop 1.0.2-beta.2)
iPhone 6 IOS 10.3.2

Hi @NirBY

the section “For iOS” was prepared for UIAutomation.

I guess you are using XCUITest with those versions. For XCUITest I can read outside of app I’m testing, so I just open notification panel and read SMS directly from there.

Hi Telmo
For XCUITest when I open notification panel to read SMS directly from there
the appium logs send error:

[debug] [XCUITest] Connection to WDA timed out

[debug] [iProxy] recv failed: Operation not permitted

I can not find msg locator
when I close notification WDA return to work

I tried this but getting an error. I have already installed the App and configured to “Accept”. So have commented out the code.

ExtractCode eCode = new ExtractCode(driver);
// eCode.configureSMSAPK();
String mySMS = eCode.returnSMS();
// eCode.uninstallSMSAPK();

I am getting the error: ava.lang.Exception: The following id was not found: net.everythingandroid.smspopup:id/popupMessageMainlayout
But i see the pop on the mobile phone running the case.

I had opened a WebApp which sent an sms and I am trying to read it.
Do i need to explicitly pass control to this pop? How?
If not, what can be wrong. Please help.

automate it like its your app… open inspector you prefer, see elements and try to found them in debug mode.

I am using the same smspopup app from playstore which you had used. It throws me the following error:
java.lang.Exception: The following id was not found: net.everythingandroid.smspopup:id/popupMessageMainlayout

while uiinspectorviewer shows me that this is present.

Try to inspect in debug mode directly from your IDE. If its present on uiautomatorviewer, it should appear also during automation.

I think I am not able to switch from my webApp to this view. Donno how to do it.