Read More
Read now

Fetching OTP(one time password) from message

Save

All of us have seen a plenty of applications that use OTP for login process but pretty much of them access your message and fill the OTP in its place by itself and we just loved it because it saves our work and time. We don’t have to put our application in background and then note the OTP and come back or even go to notification bar to know the OTP. So basically this feature is quiet interesting. Today I will show you how you can implement this in your android application.

Firstly and for mostly we have to create a BroadcastReceiver which will process the message for us. So lets create a receiver named ReceiveMessage

As you can see onReceive we have extracted the message, you can add regular expressions to get the exact code your server is sending, and instantialtied our activity to call a method onRecieveOPT(String). So we are implementing our Activity and this method in it.

So we declared our activity as well as method. You can see here I had put the whole text as it is in EditText. But as I said you can apply a regular expression to extract only code. Also be sure to mention your receiver in manifest file with proper permissions.

And you are ready to receive your OTP directly in your application.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

Deniel Kerr

Owner and Founder. Opencart

Talk to Sales
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home