Reputation: 25
Dependencies
implementation("com.google.android.gms:play-services-ads-identifier:18.0.1")
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation("com.moengage:rich-notification:5.0.1")
implementation("com.moengage:push-amp:4.6.1")
implementation("com.github.bumptech.glide:glide:4.9.0")
annotationProcessor("com.github.bumptech.glide:compiler:4.9.0")
implementation("com.google.android.gms:play-services-tagmanager:18.0.4")
implementation "androidx.core:core-ktx:1.13.1"
implementation 'com.google.android.gms:play-services-auth-api-phone:18.0.1'
` Method channel to start the receiver
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, SmsChannel)
.setMethodCallHandler { call, result ->
when (call.method) {
"listenForCode" -> try {
pendingResult = result
receiver = MySMSBroadcastReceiver()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val intentFilter = IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION)
context.registerReceiver(
receiver,
intentFilter,
SmsRetriever.SEND_PERMISSION,
null,
ContextCompat.RECEIVER_NOT_EXPORTED
)
} else {
val intentFilter = IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION)
context.registerReceiver(
receiver,
intentFilter,
SmsRetriever.SEND_PERMISSION,
null,
)
}
startListening()
} catch (e: Exception) {
Log.e(Tag, "listenForCode exception: ${e}")
}
"stopListeningForOTPCode" -> {
unregister(receiver)
result.success(null)
}
"getAppSignature" -> {
Log.i(Tag, "getAppSignature: started")
val signature = AppSignatureHelper(context).getAppSignature()
Log.i(Tag, "getAppSignature: $signature")
result.success(signature);
}
else -> {
result.notImplemented()
}
}
}
'
Broadcast receiver class
class MySMSBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
try {
if (intent != null && SmsRetriever.SMS_RETRIEVED_ACTION == intent.action && intent.extras != null ) {
val extras = intent.extras
val status : Status? = extras?.get(SmsRetriever.EXTRA_STATUS) as Status?
unregister(receiver)
if (status != null) {
when (status.statusCode) {
CommonStatusCodes.SUCCESS -> {
sms = extras?.getString(SmsRetriever.EXTRA_SMS_MESSAGE) as String
ignoreIllegalState {
val regex = Regex("\\b\\d{4,6}\\b")
val matches = regex.findAll(sms!!)
val result = matches.map { it.value }.toList()
pendingResult?.success(result[0])
}
}
CommonStatusCodes.TIMEOUT -> {
Log.e(Tag, "onReceive Timeout ")
}
}
}
}
} catch (e : Exception) {
Log.e(Tag, "onReceive Exception ${e}")
}
}
}
We have identified issue affecting the OTP auto-populate functionality using SMS retriever api on Samsung S23 Ultra in our flutter app. Users encounter a persistent error message “There is a problem connecting . Please Try again”, degrading the experience, though it is not creating a functional barrier .
We tried to use SMS-Autofill package and we could reproduce the issue . We also tried the Native Approach ( SMS Retreiver API , Method Channel) which again created the issue .
Looking for solutions to help .
Here is error from the app. You can see error message popup. Error message comes as soon as Mobile received SMS in Samsung message.
if " class MySMSBroadcastReceiver : BroadcastReceiver() {" is defined in the code it throws above mentioned error.ifthis class is not implemented error popup will not come
Also we are not able to catch the error and seems it is coming from OS.
Upvotes: 1
Views: 157