Значение getOtpInterface устанавливается при вызове метода из фрагмента. Но когда я получаю OTP и вызываю метод setOtp, значение getOtpInterface отображается как ноль.
class SMSBroadcastReceiver: BroadcastReceiver() {
private var otp: String? = null
var getOtpInterface: GetOtpInterface? = null
override fun onReceive(context: Context?, intent: Intent?) {
if (SmsRetriever.SMS_RETRIEVED_ACTION == intent?.action) {
val extras = intent?.extras
if (extras != null) {
val status = extras.get(SmsRetriever.EXTRA_STATUS) as Status
when (status.statusCode) {
CommonStatusCodes.SUCCESS -> {
val message = extras.get(SmsRetriever.EXTRA_SMS_MESSAGE) as String
val pattern = Pattern.compile("\\d{6}")
val matcher = pattern.matcher(message)
if (matcher.find()) {
otp = matcher.group(0)
getOtpInterface?.setOtp(otp!!)
}
}
CommonStatusCodes.TIMEOUT -> {
}
}
}
}
}
fun setOtpListener(getOtpInterface: GetOtpInterface) {
this.getOtpInterface = getOtpInterface
}
interface GetOtpInterface {
fun setOtp(otp: String)
}
}