public final class SinchVerification extends Object
// Create a configuration
Config config = SinchVerification.config().applicationKey("your-app-key").context(getApplicationContext()).build();
// Create the verification process listener
VerificationListener listener = new VerificationListener() {
@Override
public void onInitiated() {
// Update UI here if needed to show verification progress.
}
@Override
public void onInitiationFailed(Exception e) {
if (e instanceof InvalidInputException) {
// Incorrect number provided, ask the user to input number again.
} else if (e instanceof ServiceErrorException) {
// Another service error, please report the error message to the developers.
} else {
// Other system error.
}
}
@Override
public void onVerified() {
// Update UI for the successful case here.
}
@Override
public void onVerificationFailed(Exception e) {
if (e instanceof InvalidInputException) {
// Incorrect number or code provided, ask the user to input number again.
} else if (e instanceof CodeInterceptionException) {
// Intercepting the verification code automatically failed, try to verify manually.
verification.verify(userTypedCode);
} else if (e instanceof IncorrectCodeException) {
// The verification code provided was incorrect. Ask the user to type it again.
verification.verify(userTypedCode);
} else if (e instanceof ServiceErrorException) {
// Another service error, please report the error message to the developers.
} else {
// Other system error.
}
}
}
// Create sms verification
Verification verification = SinchVerification.createSmsVerification(config, phoneNumber, listener);
// Or create a flash call verification
Verification verification = SinchVerification.createFlashCallVerification(config, phoneNumber, listener);
// Initiate the verification process. If initiation is successful, onInitiated() callback
// will be executed and the verification code interceptor will be started automatically. When
// it receives a call or sms, it will try to call verify() with that code and in case of success
// execute the onVerified() callback.
verification.initiate();
| Constructor and Description |
|---|
SinchVerification() |
| Modifier and Type | Method and Description |
|---|---|
static ConfigBuilder |
config()
Creates a config builder.
|
static Verification |
createFlashCallVerification(Config config,
String number,
String custom,
VerificationListener listener)
Creates a flash call verification object.
|
static Verification |
createFlashCallVerification(Config config,
String number,
VerificationListener listener)
Creates a flash call verification object.
|
static Verification |
createSmsVerification(Config config,
String number,
String custom,
VerificationListener listener)
Creates an sms verification object.
|
static Verification |
createSmsVerification(Config config,
String number,
VerificationListener listener)
Creates an sms verification object.
|
static String |
getVersion() |
public static ConfigBuilder config()
ConfigBuilder object.public static Verification createSmsVerification(Config config, String number, VerificationListener listener)
config - a Confignumber - the number to be verifiedlistener - a VerificationListenerVerification object for sms verification.IllegalArgumentException - if number is null or if listener is null.public static Verification createSmsVerification(Config config, String number, String custom, VerificationListener listener)
config - a Confignumber - the number to be verifiedcustom - opaque data that will be passed in any callbacks from the Sinch backend to the applications
backendlistener - a VerificationListenerVerification object for sms verification.IllegalArgumentException - if number is null or if listener is null.public static Verification createFlashCallVerification(Config config, String number, VerificationListener listener)
config - a Confignumber - the number to be verifiedlistener - a VerificationListenerVerification object for flash call verification.IllegalArgumentException - if number is null or if listener is null.public static Verification createFlashCallVerification(Config config, String number, String custom, VerificationListener listener)
config - a Confignumber - the number to be verifiedcustom - opaque data that will be passed in any callbacks from the Sinch backend to the applications
backendlistener - a VerificationListenerVerification object for flash call verification.IllegalArgumentException - if number is null or if listener is null.public static String getVersion()