Mukie
Mukie

Reputation: 129

OTP detection in an app WebView

Is there any way to automatically detect OTP in a webview? There is a mobile no. to be verified using a an OTP and OTP is to be detected in in app webview.

Thanks in advance

Upvotes: 3

Views: 3346

Answers (2)

Gaurav Singh
Gaurav Singh

Reputation: 1

Here the code in Kotlin:

if (Build.VERSION.SDK_INT >= 19) {
            mWebView!!.evaluateJavascript(getString(R.string.fill_otp) + "\"$extractedOTP\";") { Log.e(TAG, it) }
        } else {
            mWebView!!.loadUrl(getString(R.string.fill_otp) + "\"$extractedOTP\";")
        }

Put "fill_otp" in strings file:

<string name="fill_otp">javascript: function getInputs() {
    var ary = [];
    var inputs = document.getElementsByTagName(\"input\");

    for (var i=0; i&lt;inputs.length; i++)
        {
            if (inputs[i].type.toLowerCase() == \"password\"||
            inputs[i].type.toLowerCase() == \"tel\"||
            inputs[i].type.toLowerCase() == \"number\"||
            inputs[i].type.toLowerCase() == \"text\"){

                if(!inputs[i].hidden&amp;&amp;!inputs[i].disabled){
                    ary.push(inputs[i]);
                }
            }
        }
        return ary;
    }
    var array= getInputs();
    array[0].value=</string>

Upvotes: 0

Sameer Jani
Sameer Jani

Reputation: 1040

Whenever you get OTP via sms and notify by receiver, then inside webview whichever input text inside you want to add your OTP there you need to do something like this?

String otp = "OTP_FROM_YOUR_RECEIVER";
webview.loadUrl("javascript:document.getElementById('otp_input').value = '"+otp+"';"); 

Above code is just example you need to change as per your requirements and all.

Upvotes: 2

Related Questions