VVB
VVB

Reputation: 7641

Wrong Callback gets fired while verifying received OTP using Sinch SMS Verification in android

I am integrating Sinch SMS Verification API in my app and half part is already done. So far, I am able to send and generate OTP request/response for given mobile number and receiving on that mobile number. However, when I try to VERIFY that received OTP wrong Callback gets fired.

Below is my code,

public class MainActivity extends AppCompatActivity implements OnClickListener, VerificationListener {

    private EditText editTextVerify;
    private Button buttonVerify;

    private Config config;
    private Verification verification;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editTextVerify = (EditText) findViewById(R.id.editTextVerify);
        buttonVerify = (Button) findViewById(R.id.buttonVerify);
        buttonVerify.setOnClickListener(this);

        config = SinchVerification.config().applicationKey("5xxxxx9c-xxc-4***-a***-76xxxxxb1xx1").context(getApplicationContext()).build();
        verification = SinchVerification.createSmsVerification(config, "91xx**xx**", this);
        verification.initiate();
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        System.out.println("...button clicked...");
        verification.verify(editTextVerify.getText().toString().trim());
    }

    @Override
    public void onInitiated() {
        // TODO Auto-generated method stub
        System.out.println("...calls onInitiated...");
    }

    @Override
    public void onInitiationFailed(Exception e) {
        // TODO Auto-generated method stub
        if (e instanceof InvalidInputException) {
            // Incorrect number provided
            System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
        } else if (e instanceof ServiceErrorException) {
            // Sinch service error
            System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
        } else {
            // Other system error, such as UnknownHostException in case of network error
            System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
        }
    }

    @Override
    public void onVerified() {
        // TODO Auto-generated method stub
        System.out.println("...callls onVerified this....");
    }

    @Override
    public void onVerificationFailed(Exception e) {
        // TODO Auto-generated method stub
        if (e instanceof InvalidInputException) {
            // Incorrect number or code provided
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        } else if (e instanceof CodeInterceptionException) {
            // Intercepting the verification code automatically failed, input the code manually with verify()
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        } else if (e instanceof IncorrectCodeException) {
            // The verification code provided was incorrect
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        } else if (e instanceof ServiceErrorException) {
            // Sinch service error
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        } else {
            // Other system error, such as UnknownHostException in case of network error
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        }
    }

}

Whenever I enter received OTP or wrong OTP in the Text Box & click Submit button below callback gets fired this Callback

@Override
public void onInitiationFailed(Exception e) {
    // TODO Auto-generated method stub
    if (e instanceof InvalidInputException) {
        // Incorrect number provided
        System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
    } else if (e instanceof ServiceErrorException) {
        // Sinch service error
        System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
    } else {
        // Other system error, such as UnknownHostException in case of network error
        System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
    }
}

Ideally, it should fire below Callback

@Override
public void onVerificationFailed(Exception e) {
    // TODO Auto-generated method stub
    if (e instanceof InvalidInputException) {
        // Incorrect number or code provided
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    } else if (e instanceof CodeInterceptionException) {
        // Intercepting the verification code automatically failed, input the code manually with verify()
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    } else if (e instanceof IncorrectCodeException) {
        // The verification code provided was incorrect
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    } else if (e instanceof ServiceErrorException) {
        // Sinch service error
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    } else {
        // Other system error, such as UnknownHostException in case of network error
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    }
}

Referred links : https://www.sinch.com/docs/verification/android/#verificationlistener

Upvotes: 1

Views: 507

Answers (1)

Caren García
Caren García

Reputation: 138

I would try placing the onVerified callback right after the onInitiationFailed method. This should then allow the OTP response to pass through the onVerificationFailed callback.

Here's the documentation for the Verification Listener: http://download.sinch.com/docs/verification/android/latest/reference/index.html

Upvotes: 1

Related Questions