Android SDK Integration Guide
Overview
The MTVerify Android SDK is a mobile number authentication SDK that provides fast, secure, carrier-grade phone number verification.
Key Features
- SDK initialization: Automatically fetch configuration and initialize via AppKey
- Coverage check: Check whether the current network environment supports the authentication service
- Number authentication: Initiate mobile number authentication and obtain an authentication token
System Requirements
- Android 5.0 (API 21) and above
- The user's device has mobile data enabled
Integration Guide
Permission Configuration
The aar package requests the following permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Carrier Configuration
Because the carrier interface requires HTTP plaintext transmission, you need to configure the network security policy in your application's AndroidManifest.xml:
<application
android:networkSecurityConfig="@xml/mtverify_network_security_config"
...>
...
</application>
You also need to copy the mtverify_network_security_config.xml file to your application's res/xml/ directory. You can find this file in the installation package you downloaded.
Method List
- setLogEnable - Set the log switch
- init - Initialize the SDK
- checkCoverage - Check coverage
- startAuthentication - Perform authentication
init
Initialize the MTVerify SDK and set the app key and environment configuration.
Method Signature
@JvmStatic
fun init(
context: Context,
appkey: String,
environment: IPEnvironment = IPEnvironment.PRODUCTION,
callback: InitCallback? = null
)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| context | Context | Yes | Android context object |
| appkey | String | Yes | App key, used to identify the app |
| environment | IPEnvironment | No | Environment type, defaults to SANDBOX. Options: - IPEnvironment.SANDBOX: test/sandbox environment - IPEnvironment.PRODUCTION: production environment |
| callback | InitCallback? | No | Initialization callback interface, used to receive the initialization result |
Return Value
None
Callback Result
The initialization result is returned via InitCallback.onComplete(result: InitResult):
data class InitResult(
val code: Int, // Status code; 0 means success, other numbers mean failure
val message: String? // Message (success or error message)
)
Usage Example
MTVerifyApi.init(
context = this,
appkey = "your_app_key",
environment = IPEnvironment.PRODUCTION,
callback = object : InitCallback {
override fun onComplete(result: InitResult) {
if (result.code == 0) {
// Initialization succeeded
Log.d("MTVerify", "Init succeeded: ${result.message}")
} else {
// Initialization failed
Log.e("MTVerify", "Init failed: ${result.message}")
}
}
}
)
Notes
- You must call the
init()method to initialize the SDK before using other features - The initialization process fetches
clientIdandredirectUrlvia an HTTP request and requires a network connection
setLogEnable
Set the log switch to control the SDK's log output.
Method Signature
@JvmStatic
fun setLogEnable(enable: Boolean)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| enable | Boolean | Yes | true enables logging, false disables all log output |
Usage Example
// Enable logging
MTVerifyApi.setLogEnable(true)
// Disable logging
MTVerifyApi.setLogEnable(false)
checkCoverage
Check whether the specified mobile number supports the IPification verification service.
Method Signature
@JvmStatic
fun checkCoverage(
context: Context,
phoneNumber: String,
callback: CoverageCallback? = null
)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| context | Context | Yes | Android context object |
| phoneNumber | String | Yes | Country code + user's mobile number |
| callback | CoverageCallback? | No | Coverage check callback interface |
Return Value
None
Callback Result
The check result is returned via CoverageCallback.onComplete(result: CoverageResult):
data class CoverageResult(
val code: Int, // Status code; 0 means success, other numbers mean failure
val isAvailable: Boolean, // Whether available (supported carrier)
val operatorCode: String?, // Carrier code
val message: String? // Message (success or error message)
)
Usage Example
MTVerifyApi.checkCoverage(
context = this,
phoneNumber = "6281234567890",
callback = object : CoverageCallback {
override fun onComplete(result: CoverageResult) {
if (result.code == 0) {
if (result.isAvailable) {
// Service is supported
Log.d("MTVerify", "Carrier supported: ${result.operatorCode}")
} else {
// Service is not supported
Log.d("MTVerify", "Carrier not supported")
}
} else {
// Check failed
Log.e("MTVerify", "Check failed: ${result.message}")
}
}
}
)
startAuthentication
Start the mobile number authentication flow.
Method Signature
@JvmStatic
fun startAuthentication(
activity: Activity,
countryCode: String,
phoneNumber: String,
callback: AuthenticationCallback? = null
)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| activity | Activity | Yes | Android Activity object, used to display the authentication UI |
| countryCode | String | Yes | Country code |
| phoneNumber | String | Yes | User's mobile number (without country code) |
| callback | AuthenticationCallback? | No | Authentication callback interface |
Return Value
None
Callback Result
The authentication result is returned via AuthenticationCallback.onComplete(result: AuthenticationResult):
data class AuthenticationResult(
val code: Int, // Status code; 0 means success, -1 means failure, -2 means user canceled
val token: String?, // Encrypted authentication data (a JSON string containing the code, AES-encrypted)
val message: String? // Message (success or error message)
)
Note: token is an encrypted JSON string in the following format:
{
"version": "1",
"content": {
"code": "auth code",
"state": "state parameter",
"appkey": "app key"
}
}
Usage Example
MTVerifyApi.startAuthentication(
activity = this,
countryCode = "62",
phoneNumber = "81234567890",
callback = object : AuthenticationCallback {
override fun onComplete(result: AuthenticationResult) {
when (result.code) {
0 -> {
// Authentication succeeded
val token = result.token
// The token is used to exchange for the result
Log.d("MTVerify", "Auth succeeded: $token")
}
-1 -> {
// Authentication failed
Log.e("MTVerify", "Auth failed: ${result.message}")
}
-2 -> {
// User canceled
Log.d("MTVerify", "User canceled authentication")
}
}
}
}
)
Data Models
IPEnvironment
Environment type enum:
enum class IPEnvironment {
SANDBOX, // Test/sandbox environment
PRODUCTION // Production environment
}
InitResult
Initialization result:
data class InitResult(
val code: Int, // Status code; 0 means success
val message: String? // Message
)
CoverageResult
Coverage check result:
data class CoverageResult(
val code: Int, // Status code; 0 means success
val isAvailable: Boolean, // Whether available
val operatorCode: String?, // Carrier code
val message: String? // Message
)
AuthenticationResult
Authentication result:
data class AuthenticationResult(
val code: Int, // Status code; 0 means success, -1 means failure, -2 means user canceled
val token: String?, // Encrypted authentication token
val message: String? // Message
)
Callback Interfaces
InitCallback
Initialization callback interface:
interface InitCallback {
fun onComplete(result: InitResult)
}
CoverageCallback
Coverage check callback interface:
interface CoverageCallback {
fun onComplete(result: CoverageResult)
}
AuthenticationCallback
Authentication callback interface:
interface AuthenticationCallback {
fun onComplete(result: AuthenticationResult)
}
Complete Example
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// 1. Enable logging (optional)
MTVerifyApi.setLogEnable(true)
// 2. Initialize the SDK
MTVerifyApi.init(
context = this,
appkey = "your_app_key",
environment = IPEnvironment.SANDBOX,
callback = object : InitCallback {
override fun onComplete(result: InitResult) {
if (result.code == 0) {
// Initialization succeeded; you can start using other features
checkCoverage()
}
}
}
)
}
private fun checkCoverage() {
// 3. Check coverage
MTVerifyApi.checkCoverage(
context = this,
phoneNumber = "6281234567890",
callback = object : CoverageCallback {
override fun onComplete(result: CoverageResult) {
if (result.isAvailable) {
// 4. If supported, perform authentication
startAuthentication()
}
}
}
)
}
private fun startAuthentication() {
// 5. Perform authentication
MTVerifyApi.startAuthentication(
activity = this,
countryCode = "62",
phoneNumber = "81234567890",
callback = object : AuthenticationCallback {
override fun onComplete(result: AuthenticationResult) {
if (result.code == 0) {
// Authentication succeeded; handle the token
handleToken(result.token)
}
}
}
)
}
private fun handleToken(token: String?) {
// Call the API to handle the exchanged token
}
}
Notes
- Initialization order: You must call the
init()method to initialize the SDK before using other features. - Thread safety: All API methods can be called on the main thread, and callbacks are also executed on the main thread.
- Permission requirements: Make sure the app has requested the necessary network permissions.
- Token decryption: The token returned after successful authentication is encrypted and must be processed using the corresponding decryption method.
- Log control: It is recommended to disable log output in the production environment to improve performance and security.
Version Information
- SDK version: 1.0.1










