2015-10-29 3 views
1

Я интегрирую Sinch SMS Verification API в своем приложении, а половина уже выполнена. До сих пор я могу отправлять и генерировать запрос/ответ OTP для данного мобильного номера и получать на этом мобильном телефоне. Тем не менее, когда я пытаюсь ПРОВЕРИТЬ, что получил OTP, неправильный Callback будет запущен.Неверный обратный вызов запускается при проверке полученного OTP с использованием Sinch SMS Verification в android

Ниже мой код,

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()); 
     } 
    } 

} 

Всякий раз, когда я вхожу получил OTP или неправильный OTP в текстовом поле & нажмите кнопку Отправить ниже обратного вызова увольняют этот обратный вызов

@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 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()); 
    } 
} 

Ссылки по теме: https://www.sinch.com/docs/verification/android/#verificationlistener

ответ

1

Я хотел бы попробовать Помещая onVerified обратного вызова сразу после onInitiationFailed метод. Затем это должно позволить ответ OTP проходить через обратный вызов onVerificationFailed.

Вот документация для Слушателя проверки: http://download.sinch.com/docs/verification/android/latest/reference/index.html

+0

Пробовал как вы предложили, но не работал. Проверьте вопрос, отредактировав предложенный вами способ. Не работает – VVB

Смежные вопросы