How to Retrieve OTP Message Notification from Message App to Native App

I’m new to Appium, Learning on my Own. I’m working on Native App, where the application needs to login with OTP Notification Message. In the App have to Register with Mobile Number, after entering Mobile Number, Will Receive OTP Message Notification to the entered Mobile Number.
I’m facing issue in Retrive OTP from the Message App and entering it to the Native App for login.
How to switch to Message App and fetch the OTP. After fetching how to switch back to Native App which need to Login with OTP.

Kindly guide me in resolving this problem. I have searched in most of the post, but didnt find any proper solution anywhere.

Appreciate your Help.


You can use startActivity() Method to switch your application to message app. For more info :

Hi Chirag,
Thank you so much for your Reply.

I will try with StartActivity() method. using this method is it possible to switch to message app, after fetching OTP how to switch back to native android app.

I’m switching to messahe app using below snippet:

StartAvtivity(app package, appactivity, boolean true)- will this switch to message app, after retriving if make boolean as false will driver switch back to native app which was previously?


I just use below code to switch the application:
driver.startActivity(“”, “”);

and work on the dialer application then again switch to my app then use same method with proper package and activity.

Hope this help you!!