2

I am working on a small android project. In onReceive method I tried to put a breakpoint, but no matter what I do, the breakpoint never hits. Everything in onReceive is working nicely but I can't seem to understand why breakpoint is not getting hit.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class NotiActivity extends BroadcastReceiver {

    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";

    public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equals(SMS_RECEIVED)) {
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                // get sms objects
                Object[] pdus = (Object[]) bundle.get("pdus");
                if (pdus.length == 0) {
                    return;
                }
                // large message might be broken into many
                SmsMessage[] messages = new SmsMessage[pdus.length];
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < pdus.length; i++) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    sb.append(messages[i].getMessageBody());
                }
                String message = sb.toString();
                String[] indstr = message.split(" ");

                if (indstr[0].equals("fmcqr")) {
                    DatabaseHandler db = new DatabaseHandler(context);
                    db.addOrder(new Orders(indstr[2], indstr[3], 1));
                    for(int i = 0; i < indstr.length; i++)
                    Toast.makeText(context, indstr[i], Toast.LENGTH_SHORT).show();
                    // prevent any other broadcast receivers from receiving broadcast
                    // abortBroadcast();
                }

                Toast.makeText(context, indstr[0], Toast.LENGTH_SHORT).show();
            }
        }
    }
}

Here is the code, I tried a breakpoint on every line.

atalpha
  • 320
  • 1
  • 7
  • 19

1 Answers1

-1

You need to specify permission :

<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>

Or you can refer - What is the Android sent sms intent?

Community
  • 1
  • 1
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
  • As I stated earlier, everything is working just fine. I already have done this, the problem is that I can't hit a breakpoint. – atalpha Aug 15 '14 at 21:25