A message triggers the broadcast only if it meets these criteria:
-
The message contains a 4-10 character alphanumeric string with at least one number.
-
The message was sent by a phone number that's not in the user's contacts.
-
If you specified the sender's phone number, the message was sent by that number.
Sample message : Your verification code is 1234
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.applogistdev:ALSmsRetriever-android:lastVersion'
}
Usage with SMS User Consent API (https://developers.google.com/identity/sms-retriever/user-consent/overview)
Register your listener
OneTapSmsReceiver.instance?.start(this,this, object :
OneTapSmsListener {
override fun onSuccess(message: String) {
Log.d("onSuccess", message)
}
override fun onFailure(errorCode: Int) {
Log.e("onFailure", errorCode.toString())
}
})
Add onActivityResult
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
OneTapSmsReceiver.instance?.handleOnActivityResult(requestCode,resultCode,data)
super.onActivityResult(requestCode, resultCode, data)
}
Usage with SMS Retriever API (https://developers.google.com/identity/sms-retriever/overview)
Create your Debug or Release signature with AppSignatureHelper (IMPORTANT: When you release at Google Play with Google App Signing this Release signature won't work.)
AppSignatureHelper(this).appSignatures.toString()
You must send your message with this signature. Sample: "Yumm! Pie à la Android mode! 123456 1Ouzi0b+Kxq"
Register your listener
SmsRetrieverReceiver.instance?.start(this,this, object : SmsRetrieverListener{
override fun onReceive(message: String) {
Log.d("message", message)
}
override fun onFailure(errorCode: Int) {
Log.e("onFailure", errorCode.toString())
}
})