Mobile application: how to show OTP my application sends a pop-up window without leaving my application?

We had to encode OTP based authentication. I saw some applications, such as my banking application, which, when it sends OTP, also immediately makes a quick pop-up message of the newly appeared SMS, so I see OTP without leaving the application. I just remember the number, close the pop-up window and get the login inside this application.

How do they do it? Is there some kind of iOS / Android specification that I have to look at that allows us to also pop up OTP without having to go to the SMS screen and then return to our application? Thank you

EDIT: I have very useful suggestions for Android. Now we are looking for the iOS options for these recommendations. Understand iOS has much stricter sandbox restrictions, so can a listener be more complicated?

+7
android authentication ios otp
source share
3 answers

Below is a step-by-step description to achieve your requirement.

  • Declare a receiver in AndroidManifest

    <receiver android:name=".IncomingSms"> <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> 

    2 Give permission to read SMS in AndroidManifest

      <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> <uses-permission android:name="android.permission.READ_SMS" /> 

Full code for AndroidManifest.xml File:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidexample.broadcastreceiver" android:versionCode="1" android:versionName="1.0" > <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.androidexample.broadcastreceiver.BroadcastNewSms" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="com.androidexample.broadcastreceiver.IncomingSms"> <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> </application> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> <uses-permission android:name="android.permission.READ_SMS" /> </manifest> 

Full code for the IncomingSms.java file:

 public class IncomingSms extends BroadcastReceiver { // Get the object of SmsManager final SmsManager sms = SmsManager.getDefault(); public void onReceive(Context context, Intent intent) { // Retrieves a map of extended data from the intent. final Bundle bundle = intent.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdusObj.length; i++) { SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); String phoneNumber = currentMessage.getDisplayOriginatingAddress(); String senderNum = phoneNumber; String message = currentMessage.getDisplayMessageBody(); Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message); // Show Alert int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, "senderNum: "+ senderNum + ", message: " + message, duration); toast.show(); } // end for loop } // bundle is null } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" +e); } } } 

register above the broadcast receiver in your activity and you will get your result

+10
source share

For android you need to use SMSListener as pointed out by @rushabh. You can check out a great example here.

+1
source share

Some tips to achieve your mentioning task for your application.
Step - 1 create an account with the required field, for example, username, password and otp and Login button.

Step - 2 When the user fills in the username and password, make a call to the web service. with input parameters (username and password) authenticate the values ​​if true means sending your OTP number in response to an error response message.

Step -3, if the answer is a number, means creating an AlertBuilder for Pop window to show your OTP number in the same action. Step - 4 the user saw the OTP in the login account itself and enters the OTP in the opt ie (EditText) area.

Step - 5 When the user clicks the login button, authenticate the OTP value. and go to the next operation.

+1
source share

All Articles