2

This is the code I am using in my android app's service.

Android 4.3: it works perfectly fine and I am able to get both the pending intents.

Android 4.4+: it does send out SMS, I am able to get "SMS SENT" broadcast message, but not getting the "SMS DELIVERED" broadcast. I am not receiving SMS in my app. just sending it out using smsmanager. but I need to track if the SMS was delivered or not. Please let me know if I am missing anything here,

Thanks,

Here is the code i am using in my service:

***code I am using to send sms***

String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

PendingIntent sentPI = PendingIntent.getBroadcast(getBaseContext(), 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(getBaseContext(), 0, new Intent(DELIVERED), 0);

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);

***boradcast receiver for SMS SENT intent***
sendBroadcastReceiver = new BroadcastReceiver()
        {
            @Override
            public void onReceive(Context arg0, Intent arg1) {

                switch (getResultCode())
                {
                case Activity.RESULT_OK:
                    Log.d(TAG, "SMS Activity: SMS Sent");
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Log.d(TAG, "SMS Activity: ERROR (GENERIC FAILURE)");
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Log.d(TAG, "SMS Activity: ERROR (NO SERVICE)");
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Log.d(TAG, "SMS Activity: ERROR (NULL PDU)");
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Log.d(TAG, "SMS Activity: ERROR (RADIO OFF)");
                    break;
                default:
                    Log.d(TAG, "SMS Activity: DEFAULT");
                    break;
                }
            }
        };

***code for sms delivery intent broadcast receiver***

deliveredBroadcastReceiver = new BroadcastReceiver()
        {
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                Log.d(TAG,"SMS DELIVERY INTENT RECEIVED");

                switch (getResultCode())
                {
                case Activity.RESULT_OK:
                    Log.d(TAG,"SMS DELIVERY: OK");
                    break;
                case Activity.RESULT_CANCELED:
                    Log.d(TAG,"SMS DELIVERY: CANCELED");
                    break;
            }

            }
        };


***Registering the receivers on Start Service()***

       registerReceiver(sendBroadcastReceiver , new IntentFilter("SMS_SENT"));
       registerReceiver(deliveredBroadcastReceiver , new IntentFilter("SMS_DELIVERED"));

***Unregistering the receivers on Stop Service()***

       unregisterReceiver(sendBroadcastReceiver);
       unregisterReceiver(deliveredBroadcastReceiver);
user1720839
  • 91
  • 2
  • 8

1 Answers1

1

SMS changed significantly with 4.4, see https://developer.android.com/about/versions/android-4.4.html#SMS

Only the default SMS Provider will ever receive an SMS_DELIVER_ACTION and several other events. I think you're hitting these cases.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127