Ola Money Developer Hub

Welcome to the Ola Money developer hub. You'll find comprehensive guides and documentation to help you start working with Ola Money as quickly as possible, as well as support if you get stuck.

Documentation

Auto Read OTP

Why not delight your customer with our auto read OTP feature on android? Here is how you can do that:

Step 1: Add a permission to receive SMS

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

Step 2: SMS receiver

Copy this SMS receiver onto your web view containing activity.

private BroadcastReceiver smsReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        SmsMessage[] smsMessages = null;

        if (bundle != null) {
            pd.dismiss();
            Object[] pdus = (Object[]) bundle.get("pdus");
            smsMessages = new SmsMessage[pdus.length];

     for(int i=0;i<smsMessages.length;i++) {
         smsMessages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
         String sender = smsMessages[i].getOriginatingAddress();
            if(sender.contains("OLAMNY") || sender.contains("olamny")) {
                    String message = smsMessages[i].getMessageBody();
                    String otp = extractOTP(message);
                    if(otp!=null) {
                        String js = "javascript: " + "document.getElementById('sample2').value = '"+otp+"';"
                                            + "document.getElementsByClassName('mdl-button')[0].click();";

                        if(webView!=null) {
                            webView.loadUrl(js);
                        }
                    }
                }
            }
        }
    }
};

public String extractOTP(String sms) {
    String[] nbs = sms.split("\\D+");
    if (nbs.length != 0) {
        for (String number : nbs) {
            if (number.matches("^[0-9]+$")) {
                return number;
            }
        }
    }
    return null;
}

Step 3: Make a fancy Waiting box. Here is one if you need it:

private ProgressDialog showDialog() {
    ProgressDialog pd = new ProgressDialog(WebViewActivity.this);
    pd.setTitle("Waiting for SMS");
    pd.setIndeterminate(true);
    pd.show();
    return pd;
}

Step 4: Remember to register the smsReceiver as follows:

IntentFilter intentFilter = new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION);
registerReceiver(smsReceiver, intentFilter);

You can unregister the same on onDestroy() of the activity:

unregisterReceiver(smsReceiver);

Auto Read OTP