Crashes when sending SMS from BroadcastReceiver
<p>I have a BroadcastReceiver that when a SMS is received it queries database and sends out appropriate SMS from database results. The problem I'm having is that it keeps crashing when I get to the part where it sends SMS </p>

<pre><code>public class SMSReceiver extends BroadcastReceiver {
    SQLiteDatabase db;
    private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
    private static String messagefrom;
    private static String messagebody;
    final String dbTable = "Realtor_SMS_Table";

    @Override
    public void onReceive(Context context, Intent intent) {

        if (intent != null &amp;&amp; intent.getAction() != null
                &amp;&amp; ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
            Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
            SmsMessage[] messages = new SmsMessage[pduArray.length];
            for (int i = 0; i &lt; pduArray.length; i++) {
                messages[i] = SmsMessage.createFromPdu((byte[]) pduArray[i]);
                messagefrom = messages[i].getOriginatingAddress();
                messagebody = messages[i].getMessageBody();
                Log.d("My SMSReceiver", "From: " + messagefrom);
                Log.d("My SMSReceiver", "Msg: " + messagebody);
                FilterMessage(dbTable, messagefrom, messagebody);

            }

            Log.d("My SMSReceiver", "SMSReceived");

        }
    }

    public void FilterMessage(String dbTable, String messagefrom,
            String messagebody) {
        String myPath = "/data/data/com.RealtorSMS/databases/RealtorDB.db";
        db = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READONLY);

        Cursor cursor = db.query(dbTable, new String[] { "_id", "Description",
                "URL" }, "_id like " + "'%" + messagebody + "%'", null, null,
                null, null);

        Log.d("My SMSReceiver", "sql= " + cursor);

        if (cursor != null) {
            cursor.moveToFirst();
            String messageAddress = null;
            String messageDescription = null;
            String messageURL = null;
            while (cursor.isAfterLast() == false) {

                messageAddress = cursor.getString(0);
                messageDescription = cursor.getString(1);
                messageURL = cursor.getString(2);

            }

            SmsManager sm = SmsManager.getDefault();
            sm.sendTextMessage(messagefrom, null, messageAddress + " "
                    + messageDescription, null, null);
            sm.sendTextMessage(messagefrom, null, messageAddress + " "
                    + messageURL, null, null);
        }

    }

}
</code></pre>

<p>Here is the logcat:</p>

<pre><code>08-10 18:19:33.796: ERROR/ActivityManager(68): ANR in com.RealtorSMS
08-10 18:19:33.796: ERROR/ActivityManager(68): Reason: Broadcast of Intent { act=android.provider.Telephony.SMS_RECEIVED cmp=com.RealtorSMS/.SMSReceiver (has extras) }
08-10 18:19:33.796: ERROR/ActivityManager(68): Load: 0.56 / 0.32 / 0.28
08-10 18:19:33.796: ERROR/ActivityManager(68): CPU usage from 5091ms to 0ms ago:
08-10 18:19:33.796: ERROR/ActivityManager(68):   82% 583/com.RealtorSMS: 81% user + 0.9% kernel / faults: 150 minor
08-10 18:19:33.796: ERROR/ActivityManager(68):   7.6% 68/system_server: 4.9% user + 2.7% kernel / faults: 5 minor
08-10 18:19:33.796: ERROR/ActivityManager(68):   5.5% 139/com.android.systemui: 5.1% user + 0.3% kernel / faults: 85 minor
08-10 18:19:33.796: ERROR/ActivityManager(68):   1.3% 136/com.android.phone: 0.5% user + 0.7% kernel / faults: 15 minor
08-10 18:19:33.796: ERROR/ActivityManager(68):   0.7% 41/adbd: 0% user + 0.7% kernel
08-10 18:19:33.796: ERROR/ActivityManager(68):   0.5% 411/com.android.mms: 0.3% user + 0.1% kernel / faults: 2 minor
08-10 18:19:33.796: ERROR/ActivityManager(68): 99% TOTAL: 93% user + 5.7% kernel
08-10 18:19:33.796: ERROR/ActivityManager(68): CPU usage from 1582ms to 2224ms later:
08-10 18:19:33.796: ERROR/ActivityManager(68):   88% 583/com.RealtorSMS: 88% user + 0% kernel
08-10 18:19:33.796: ERROR/ActivityManager(68):     88% 583/com.RealtorSMS: 88% user + 0% kernel
08-10 18:19:33.796: ERROR/ActivityManager(68):   12% 68/system_server: 6.2% user + 6.2% kernel
08-10 18:19:33.796: ERROR/ActivityManager(68):     12% 81/ActivityManager: 7.8% user + 4.6% kernel
08-10 18:19:33.796: ERROR/ActivityManager(68): 100% TOTAL: 93% user + 6.2% kernel
</code></pre>
