我一直在使用适用于 Android 的 Twilio 验证 SDK (com.twilio:verification:1.0.9) 使用此 build.gradle 配置:compile_sdk = 26、min_sdk = 23、target_sdk = 26 和 build_tools = '27.0 .3',我无法让应用程序在 Android 7.0 和 8.0 设备上读取短信;但是,它在 Android 6.0 上运行良好。
这是我的广播接收器:
class PhoneVerificationReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent) {
RxBus.publish(PhoneVerificationEvent(TwilioVerification.getVerificationStatus(intent).state))
}
}
它是这样在 AndroidManifest 上声明的:
<receiver
android:name=".service.PhoneVerificationReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.twilio.verification.current_status" />
</intent-filter>
</receiver>
这里我有订阅:
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()
}
获取 JWT token 后,验证过程开始,它成功进入 onReceive
方法,并带有 VerificationStatus.State.STARTED
。之后,收到短信,但不再进入onReceive
函数。
Android SDK 哈希签名已到位;我遵循了本教程:https://www.twilio.com/docs/verify/tutorials/android-sdk-register-your-app ;此代码在 Android 6.0 设备上运行良好。
任何帮助将不胜感激。
最佳答案
此处为 Twilio 开发人员布道师。
我不是 Android 开发人员,但我向内部团队寻求帮助,这是他们告诉我的。
Manifest 声明的广播接收器对较新版本的 Android 有一些限制。您能否在运行时使用 context.registerReceiver
注册广播接收器并使用 context.unregisterReceiver
注销。
这里有更多信息:https://developer.android.com/guide/components/broadcasts#context-registered-receivers .
让我知道这是否有帮助。
关于android - Twilio 验证 SDK 在 Android 7.0 和 8.0 上不读取短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50359905/