0

I want to check that SMS was sent after:

        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNo, null, smsText, sentPI, null);

As I've found as of now the only way is to use a receiver. Am I right?

I've found good example in post: Unable to send sms using SMSManager in Android First answer shows how to write a receiver. However, there are comments to that answer, first that more and more receivers get registered with each SMS (I have that), and second how to fix it: unregisterReceiver(this); I've tried to use unregisterReceiver; I've changed code in post above to:

BroadcastReceiver r = new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            unregisterReceiver(r);

.....

registerReceiver(r, new IntentFilter(SENT));

It works same as in example. Now I need to add unregisterReceiver(r). I've tried to put it after smsManager.sendTextMessage - receiver is not called at all. I've tried to put it in onReceive - was told to declare r as final. So did that, now "r" might not been initiated error. Where should I put unregisterReceiver to get rid of new and new receivers?

Community
  • 1
  • 1
Alex Martian
  • 3,423
  • 7
  • 36
  • 71
  • 1
    quick note, in that `onReceive` method, `unregisterReceiver(r);` could be `unregisterReceiver(this);` and `r` would not have to be final then. – petey Dec 02 '15 at 20:35

1 Answers1

0

It started to work fine after change in code @petey commented. Looks like I put unregisterReceiver(this); in other place before.

Alex Martian
  • 3,423
  • 7
  • 36
  • 71