Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get failed sms #175

Open
omarbenzekri opened this issue Jan 16, 2023 · 4 comments
Open

Can't get failed sms #175

omarbenzekri opened this issue Jan 16, 2023 · 4 comments

Comments

@omarbenzekri
Copy link

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.

@redanium
Copy link

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

@redanium
Copy link

redanium commented Jan 24, 2023

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);
    }
  }

@omarbenzekri
Copy link
Author

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

@redanium
Copy link

Sorry forgot to add FAIL to SendStatus enum
constants.dart

const SMS_FAIL = "smsFail";
enum SendStatus { SENT, DELIVERED, FAIL };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants