Reputation: 11
I've been working with the Twilio Verification SDK for Android (com.twilio:verification:1.0.9) with this build.gradle configuration: compile_sdk = 26, min_sdk = 23, target_sdk = 26, and build_tools = '27.0.3' and I haven't been able to make the app to read the SMS on Android 7.0 and 8.0 devices; however, it works fine on Android 6.0.
This is my BroadcastReceiver:
class PhoneVerificationReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent) {
RxBus.publish(PhoneVerificationEvent(TwilioVerification.getVerificationStatus(intent).state))
}
}
It's declared on AndroidManifest this way:
<receiver
android:name=".service.PhoneVerificationReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.twilio.verification.current_status" />
</intent-filter>
</receiver>
Here I have the subscription:
override fun onResume() {
super.onResume()
disposable.add(
RxBus.listen(PhoneVerificationEvent::class.java)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
when (it.state) {
VerificationStatus.State.STARTED, VerificationStatus.State.AWAITING_VERIFICATION -> {
lockUI()
}
VerificationStatus.State.SUCCESS -> {
savePhoneNumber()
}
VerificationStatus.State.ERROR -> {
unlockUI("Phone couldn\'t be verified")
}
}
}, {
Timber.e(it)
})
)
}
override fun onPause() {
disposable.clear()
super.onPause()
}
After retrieving the JWT token, the verification process starts, it successfuly enters the onReceive
method with VerificationStatus.State.STARTED
. After that, the SMS is received but it's not entering the onReceive
function anymore.
The Android SDK Hash Signature is in place; I followed this tutorial: https://www.twilio.com/docs/verify/tutorials/android-sdk-register-your-app; this code works fine on Android 6.0 devices.
Any help will be greatly appreciated.
Upvotes: 1
Views: 231
Reputation: 73090
Twilio developer evangelist here.
I am not an Android developer, but I checked with the team internally for help and here's what they told me.
Manifest declared broadcast receivers have some restrictions on newer versions of Android. Can you register the broadcast receiver at runtime using context.registerReceiver
and unregister using context.unregisterReceiver
.
There's more info here: https://developer.android.com/guide/components/broadcasts#context-registered-receivers.
Let me know if that helps at all.
Upvotes: 1