アプリに Sinch SMS Verification API を統合していますが、半分は既に完了しています。これまでのところ、特定の携帯電話番号の OTP 要求/応答を送信および生成し、その携帯電話番号で受信することができました。ただし、OTP を受信したことを確認しようとすると、間違ったコールバックが発生します。
以下は私のコードです、
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