This guide shows you how to integrate mobile number verification into your Android application and use its API.
Integration steps
Download the SDK
Log on to the Phone Number Verification Service console. On the Overview page, find the API & SDK section on the right and click Download Now. Follow the on-screen instructions to download the required SDK.
Create an authentication scheme
For more information, see Create an authentication scheme and obtain a scheme code.
Project setup
Ensure that your project meets the following environment requirements for
minSdkVersionandcompileSdkVersion.minSdkVersion: The Phone Number Verification SDK requires API level 21 or later. When you create a new project, the minSdkVersion must be 21 or higher.
compileSdkVersion: The Phone Number Verification SDK requires API level 30 or later. When you create a new project, the compileSdkVersion must be 30 or higher.

Import the aar artifacts and add dependencies.
In the module that uses the phone number verification feature, import the SDKs by copying all three AAR files into the
libsfolder.
Package starting with
auth: This is the main aar artifact, which implements the one-click logon and local number verification features.Package starting with
logger: This is the SDK's logging component and is a required dependency.Package starting with
main: This is the SDK's base functional component and is a required dependency.
In the app module (usually
app/build.gradle), add the following dependency to thedependenciescode block:implementation fileTree(dir: 'libs', include: ['*.aar']) implementation 'androidx.appcompat:appcompat:1.3.1'
Add permissions
Add permissions to your AndroidManifest.xml file.
Required permissions (These are declared in the aar file and require no separate configuration.)
<uses-permission android:name="android.permission.INTERNET" /> <!-- For internet access -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- To check the Wi-Fi state -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- To check the network state -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <!-- To change the network state -->Optional permissions (These permissions are not required for the mobile number verification feature.)
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- To read the phone state -->For more information, see Mobile number verification interaction flow.
SDK methods
Get the authentication instance
/**
* Gets the singleton instance of this class.
* @param context The Android context. The application context is recommended.
* @param tokenListener The callback for token retrieval results.
* @return The singleton instance of the class.
*/
public static PhoneNumberAuthHelper getInstance(Context context, TokenResultListener tokenResultListener)Usage example
TokenResultListener mTokenResultListener = new TokenResultListener() {
@Override
public void onTokenSuccess(String s) {
// Handle successful token retrieval.
}
@Override
public void onTokenFailed(String s) {
// Handle failed token retrieval.
}
};
PhoneNumberAuthHelper mPhoneNumberAuthHelper = PhoneNumberAuthHelper.getInstance(this, mTokenResultListener);Required method: Set SDK secret (setAuthSDKInfo)
/**
* Initializes the SDK. Call this method once during the app's lifecycle.
* @param secretInfo Your AppID, AppKey, and scheme code.
*/
public void setAuthSDKInfo(String secretInfo)Usage example
mPhoneNumberAuthHelper.setAuthSDKInfo(secretInfo);Required method: Get verification token (getVerifyToken)
Before you use this method, call the setAuthListener method.
/**
* Gets the verification token.
*
* @param totalTimeout The timeout in milliseconds (ms).
*/
public void getVerifyToken(final int totalTimeout)Usage example
mPhoneNumberAuthHelper.setAuthListener(mVerifyListener);
mPhoneNumberAuthHelper.getVerifyToken(5000);Optional method: Accelerate token retrieval (accelerateVerify)
/**
* Accelerates the mobile number verification process.
*
* @param overdueTimeMills The timeout in milliseconds (ms).
* @param listener The callback for the result.
*/
@AuthNumber
public void accelerateVerify(final int overdueTimeMills, final PreLoginResultListener listener)Usage example
mPhoneNumberAuthHelper.accelerateVerify(timeout, new PreLoginResultListener() {
@Override
public void onTokenSuccess(String vendor) {
// Handle the successful acceleration.
}
@Override
public void onTokenFailed(String vendor, String errorMsg) {
// Handle the failed acceleration.
}
});Mobile number verification example
//// 1. Create an instance.
mVerifyListener = new TokenResultListener() {
@Override
public void onTokenSuccess(String s) {
// Handle successful token retrieval.
}
@Override
public void onTokenFailed(final String s) {
// Handle failed token retrieval.
}
};
mPhoneNumberAuthHelper = PhoneNumberAuthHelper.getInstance(getApplicationContext(), mVerifyListener);
// 2. Check if the environment is ready.
mPhoneNumberAuthHelper.checkEnvAvailable(PhoneNumberAuthHelper.SERVICE_TYPE_AUTH);
// 3.1. (Optional) Accelerate verification.
mPhoneNumberAuthHelper.accelerateVerify(5000, new PreLoginResultListener() {
@Override
public void onTokenSuccess(String vendor) {
// Handle the successful acceleration.
}
@Override
public void onTokenFailed(String vendor, String errorMsg) {
// Handle the failed acceleration.
}
});
// 3.2. Get the verification token.
mPhoneNumberAuthHelper.setAuthListener(mVerifyListener);
mPhoneNumberAuthHelper.getVerifyToken(timeout);
// 4. Verify the token on your server.
// Your server must integrate with the Phone Number Verification Service and provide an API that your app calls to pass the mobile number and verification token.