Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6244037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:15:12+00:00 2026-05-24T12:15:12+00:00

I have a BroadcastReceiver that when a SMS is received it queries database and

  • 0

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

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 && intent.getAction() != null
                && ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
            Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
            SmsMessage[] messages = new SmsMessage[pduArray.length];
            for (int i = 0; i < 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);
        }

    }

}

Here is the logcat:

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:15:13+00:00Added an answer on May 24, 2026 at 12:15 pm

    You might need to move your processing logic into a separate Service: instead of invoking FilterMessage in the onReceive method, call startService and do the processing in a separate thread. The ANR is because some part of your FilterMessage function is taking too long: I expect your database open/loop/close is taking too long.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that extends BroadcastReceiver that reads new sms public class SmsReceiver
Hello I faced the same problem I have 1 broadcast receiver from that I
I have class that extends BroadcastReceiver and gets all new sms. When I get
i have this broadcastreceiver that executes some code from time to time and triggers
I have a service that starts a broadcastReceiver to listen for an SMS. If
I have a snippet of code that I'm calling from a service: context.registerReceiver(new BroadcastReceiver()
I have an app that replies to any received SMS with a default message.
I have a program that monitors incoming SMS's, and I want it to monitor
I am currently developing an app that reads out SMS/Emails while driving. Many users
I have a problem, not that major problem but since i implemented sendMultipartTextMessage on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.