SMS Consent API Library simplifies the process of integrating Google's SMS Consent API into your Android application. This library handles the complexities involved in requesting and retrieving SMS messages containing one-time passwords (OTP) and displays them within the app without interrupting the user experience.
Add the dependency below to your module's build.gradle
file:
dependencies {
implementation("com.github.burkido:auto-read-otp:1.0.3")
}
Use the SmsUserConsent
composable where you want to obtain SMS consent, such as in a screen with an OTP text field. You can see a sample implementation in the example app here.
SmsUserConsent(
smsCodeLength = OTP_LENGTH,
onOTPReceived = { otp ->
Log.d("MainActivity", "SMS Received: $otp")
code = otp
},
onError = { error ->
Log.e("MainActivity", "Error: $error")
}
)