Fetching OTP(one time password) from message

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.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close