Telephony
Telephony copied to clipboard
Can't get failed sms
is there a way to get a list of failed messages? getSentSms() without any filter doesn't get themes. I have Samsung M32 running android 12.
By checking the source code , I have noticed that this plugin handles only SENT and DELIVERED status but not the network failure or when the balance is zero
I managed to get SMS fail status when the balance is zero by modifying some files (valid for other failures).
SmsMethodCallHandler.kt
override fun onReceive(ctx: Context?, intent: Intent?) {
if (intent != null) {
when (intent.action) {
Constants.ACTION_SMS_SENT -> {
Log.e("SmsHandler","ACTION_SMS_SENT : " + resultCode.toString())
when(resultCode) {
Activity.RESULT_OK -> foregroundChannel.invokeMethod(SMS_SENT, null)
SmsManager.RESULT_ERROR_GENERIC_FAILURE -> foregroundChannel.invokeMethod(SMS_FAIL, null)
SmsManager.RESULT_ERROR_NO_SERVICE -> foregroundChannel.invokeMethod(SMS_FAIL, null)
SmsManager.RESULT_ERROR_NULL_PDU -> foregroundChannel.invokeMethod(SMS_FAIL, null)
SmsManager.RESULT_ERROR_RADIO_OFF -> foregroundChannel.invokeMethod(SMS_FAIL, null)
}
}
Constants.ACTION_SMS_DELIVERED -> {
Log.e("SmsHandler","ACTION_SMS_DELIVERED : " + resultCode.toString())
when (resultCode) {
Activity.RESULT_OK -> foregroundChannel.invokeMethod(SMS_DELIVERED, null)
Activity.RESULT_CANCELED -> foregroundChannel.invokeMethod(SMS_FAIL, null)
}
context.unregisterReceiver(this)
}
}
}
}
}
Constants.kt
const val SMS_FAIL = "smsFail"
constants.dart
const SMS_FAIL = "smsFail";
enum SendStatus { SENT, DELIVERED, FAIL };
telephony.dart
Future<dynamic> handler(MethodCall call) async {
switch (call.method) {
case ON_MESSAGE:
final message = call.arguments["message"];
return _onNewMessage(SmsMessage.fromMap(message, INCOMING_SMS_COLUMNS));
case SMS_SENT:
return _statusListener(SendStatus.SENT);
case SMS_DELIVERED:
return _statusListener(SendStatus.DELIVERED);
case SMS_FAIL:
return _statusListener(SendStatus.FAIL);
}
}
I managed to get SMS fail status when the balance is zero by modifying some files (valid for other failures).
SmsMethodCallHandler.kt
override fun onReceive(ctx: Context?, intent: Intent?) { if (intent != null) { when (intent.action) { Constants.ACTION_SMS_SENT -> { Log.e("SmsHandler","ACTION_SMS_SENT : " + resultCode.toString()) when(resultCode) { Activity.RESULT_OK -> foregroundChannel.invokeMethod(SMS_SENT, null) SmsManager.RESULT_ERROR_GENERIC_FAILURE -> foregroundChannel.invokeMethod(SMS_FAIL, null) SmsManager.RESULT_ERROR_NO_SERVICE -> foregroundChannel.invokeMethod(SMS_FAIL, null) SmsManager.RESULT_ERROR_NULL_PDU -> foregroundChannel.invokeMethod(SMS_FAIL, null) SmsManager.RESULT_ERROR_RADIO_OFF -> foregroundChannel.invokeMethod(SMS_FAIL, null) } } Constants.ACTION_SMS_DELIVERED -> { Log.e("SmsHandler","ACTION_SMS_DELIVERED : " + resultCode.toString()) when (resultCode) { Activity.RESULT_OK -> foregroundChannel.invokeMethod(SMS_DELIVERED, null) Activity.RESULT_CANCELED -> foregroundChannel.invokeMethod(SMS_FAIL, null) } context.unregisterReceiver(this) } } } } }
Constants.kt
const val SMS_FAIL = "smsFail"
constants.dart
const SMS_FAIL = "smsFail"
telephony.dart
Future<dynamic> handler(MethodCall call) async { switch (call.method) { case ON_MESSAGE: final message = call.arguments["message"]; return _onNewMessage(SmsMessage.fromMap(message, INCOMING_SMS_COLUMNS)); case SMS_SENT: return _statusListener(SendStatus.SENT); case SMS_DELIVERED: return _statusListener(SendStatus.DELIVERED); case SMS_FAIL: return _statusListener(SendStatus.FAIL); } }
thank you.I'll check it and get back to you later
Sorry forgot to add FAIL
to SendStatus
enum
constants.dart
const SMS_FAIL = "smsFail";
enum SendStatus { SENT, DELIVERED, FAIL };