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 7876521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:10:46+00:00 2026-06-03T03:10:46+00:00

I have a method to send sms. This method registers two pending intents to

  • 0

I have a method to send sms. This method registers two pending intents to receive sending and delivery reports.

I send the first message and I receive its sending and delivery reports and then send another message. While receiving reports for second message, I get reports of first message and then second message. If I send another message, I get reports of first and second messages and then for the third message.

What’s the problem?

Source:

public void sendSms(String phoneNumber, String cmd ...) {
    sentPI      = PendingIntent.getBroadcast(this, sendSmsCounter++, new Intent(SENT),      PendingIntent.FLAG_CANCEL_CURRENT);
    deliveredPI = PendingIntent.getBroadcast(this, deliverCounter++, new Intent(DELIVERED), PendingIntent.FLAG_CANCEL_CURRENT);

    sendingBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    displayMessage("Sms Sent");
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    displayMessage("Sending SMS error: Generic failure");
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    displayMessage("Sending SMS error: No service");
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    displayMessage("Sending SMS error: Null PDU");
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    displayMessage("Sending SMS error: Radio off");
                    break;
            }               
        }
    };


    this.registerReceiver(sendingBroadcastReceiver, new IntentFilter(SENT));

    deliveryBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
           switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    displayMessage("SMS Delivered");
                    break;
                case Activity.RESULT_CANCELED:
                    displayMessage("SMS delivery error: SMS Canceled");
                    break;                        
            }               
        }
    };

    this.registerReceiver(deliveryBroadcastReceiver, new IntentFilter(DELIVERED));

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, cmd, sentPI, deliveredPI);        
  • 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-06-03T03:10:47+00:00Added an answer on June 3, 2026 at 3:10 am

    problem is solved by adding this line at the end of OnReceive() methods:

     MyActivity.this.unregisterReceiver(this);
    

    Closer look:

    sendingBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    displayMessage("Sms Sent");
                    break;
                // ...    
            }
            MyActivity.this.unregisterReceiver(this);               
        }
    };
    

    After receiving broadcast and processing it, we no longer need this broadcast receiver, so we unregister that from our Activity.

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

Sidebar

Related Questions

I have a problem when trying to send a POST request. The sending method
I'm trying to write a lookup method for determining a SMS message to send
serial.write() method in pyserial seems to only send string data. I have arrays like
I have a method, that computes the number of differences in two strings, and
I have a method on my generated partial class like this: var pChildren =
I have contact list and I want to send an sms using MFMessageComposeViewController and
I have an account in a website by which I can send sms to
If I have the method public void send() { /* some code */ }
I have a menu which when fired send an SMS and from the BroadCastReciever,
I have designed for schedule SMS in android.i set timer for SMS to send

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.