Reply with SMS in Android on incoming call
<p>I've written an Android app that uses a PhoneStateListener to detect incoming calls and send an SMS message to the caller if they don't wish to be disturbed.  This works flawlessly on my HTC Evo (Sprint) with Android 2.3.3 and in the emulator.</p>

<p>A colleague is running a Droid Incredible (Verizon) with Android 2.3.3.  When running on this phone, the app gets "Message Failed.  Would you like to retry?"</p>

<p>In my sms sending code it creates PendingIntents for Sent and Delivered.  On his phone, the Sent PendingIntent isn't received until I cancel the retry dialog and the resultCode is unknown (133169).</p>

<p><b>Does anyone know what I'm doing wrong.  Is this an issue of trying to send the message while the call is incoming on this device?</b></p>

<p>`
    String SENT = "SMS_SENT";
    String DELIVERED = "SMS_DELIVERED";</p>

<pre><code>PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);

PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); // ---when the SMS has been sent---

registerReceiver(new BroadcastReceiver() {
    @Override
    public void onReceive(Context arg0, Intent arg1) {
    Log.i(DoNotDisturbApplication.TAG, "sentreceiver");

            int resultCode = getResultCode();
            switch (resultCode) {
            case Activity.RESULT_OK:
                Log.i(DoNotDisturbApplication.TAG, "SMS Sent");
                Toast.makeText(getBaseContext(), "SMS sent",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                Log.i(DoNotDisturbApplication.TAG, "Generic Failure");
                Toast.makeText(getBaseContext(), "Generic failure",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
                Log.i(DoNotDisturbApplication.TAG, "Null Service");
                Toast.makeText(getBaseContext(), "No service",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                Log.i(DoNotDisturbApplication.TAG, "Null PDU");
                Toast.makeText(getBaseContext(), "Null PDU",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                Log.i(DoNotDisturbApplication.TAG, "Radio off");
                Toast.makeText(getBaseContext(), "Radio off",
                        Toast.LENGTH_SHORT).show();
                break;
            default:
                Log.i(DoNotDisturbApplication.TAG, "Unknown result code " + resultCode);
                break;
            }
        }
    }, new IntentFilter(SENT));

    // ---when the SMS has been delivered---
    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            Log.i(DoNotDisturbApplication.TAG, "delivered receiver");
            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Log.i(DoNotDisturbApplication.TAG, "SMS delivered");
                Toast.makeText(getBaseContext(), "SMS delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            case Activity.RESULT_CANCELED:
                Log.i(DoNotDisturbApplication.TAG, "SMS not delivered");
                Toast.makeText(getBaseContext(), "SMS not delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
    }, new IntentFilter(DELIVERED));

    Log.i(DoNotDisturbApplication.TAG, "Getting SMS Manager");
    SmsManager sms = SmsManager.getDefault();
    Log.i(DoNotDisturbApplication.TAG, "Sending Text Message");
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
    Log.i(DoNotDisturbApplication.TAG, "Sent Text Message");
</code></pre>

<p>`</p>
