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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:05:04+00:00 2026-05-31T14:05:04+00:00

I am trying to send sms amd mail together. There are no issues with

  • 0

I am trying to send sms amd mail together. There are no issues with sending mail, but when i send sms I receive this Exception:

End has leaked IntentReceiver
Are you missing a call to unregisterReceiver()? 

Here is my code for sms method from https://mobiforge.com/design-development/sms-messaging-android:

public class End extends Activity {
    
    Button btnSendSMS;
    EditText txtPhoneNo;
    EditText txtMessage;
    public EditText Details;
    public String user;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.end);
        Details = (EditText)findViewById(R.id.details);
        btnSendSMS = (Button) findViewById(R.id.btnSend);
        Bundle b=this.getIntent().getExtras();
        final String email=b.getString("keym");
        final String pno=b.getString("keys");

        btnSendSMS.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {           
                String detail=Details.getText().toString();
                Mail m = new Mail("abc@gmail.com", "sdfsa"); 
                String[] toArr = {email}; 
                m.setTo(toArr); 
                m.setFrom("asdasd11@gmail.com"); 
                m.setSubject("EMERGENCY");
                m.setBody(detail);
             
                try { 
                    // m.addAttachment("/sdcard/filelocation"); 
                    if(m.send()) { 
                    Toast.makeText(End.this, "Email was sent successfully.", Toast.LENGTH_LONG).show(); 
                    } else { 
                  Toast.makeText(End.this, "Email was not sent.", Toast.LENGTH_LONG).show(); 
                    } 
                } catch(Exception e) { 
                //Toast.makeText(MailApp.this, "There was a problem sending the email.", Toast.LENGTH_LONG).show(); 
                Log.e("MailApp", "Could not send email", e); 
                } 
              
                sendSMS(pno, detail);
                finish();
                Intent intent = new Intent(End.this,Service.class);
                startActivity(intent);
               }   
            }
        );        
    
    } 

    private void sendSMS(String phoneNumber, String message)
    {        
         String SENT = "SMS_SENT";
         String DELIVERED = "SMS_DELIVERED";
  
         PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
             new Intent(SENT), 0);
  
         PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
             new Intent(DELIVERED), 0);
  
         //---when the SMS has been sent---
         registerReceiver(new BroadcastReceiver()
         {
             Context context;
             @Override
             public void onReceive(Context arg0, Intent arg1) {
                 switch (getResultCode())
                 {
                     case Activity.RESULT_OK:
                         Toast.makeText(getBaseContext(), "SMS sent", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                         Toast.makeText(getBaseContext(), "Generic failure", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case SmsManager.RESULT_ERROR_NO_SERVICE:
                         Toast.makeText(getBaseContext(), "No service", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case SmsManager.RESULT_ERROR_NULL_PDU:
                         Toast.makeText(getBaseContext(), "Null PDU", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case SmsManager.RESULT_ERROR_RADIO_OFF:
                         Toast.makeText(getBaseContext(), "Radio off", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                 }
               

             }
         }, new IntentFilter(SENT));
  
         //---when the SMS has been delivered---
         registerReceiver(new BroadcastReceiver(){
             Context context;
             @Override
            
             public void onReceive(Context arg0, Intent arg1) 
             {
                 switch (getResultCode())
                 {
                     case Activity.RESULT_OK:
                         Toast.makeText(getBaseContext(), "SMS delivered", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case Activity.RESULT_CANCELED:
                         Toast.makeText(getBaseContext(), "SMS not delivered", 
                                 Toast.LENGTH_SHORT).show();
                         break;                        
                 }
             
             }
         }, new IntentFilter(DELIVERED));        
  
         SmsManager sms = SmsManager.getDefault();
         sms.sendTextMessage(phoneNumber, null, message, 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-05-31T14:05:05+00:00Added an answer on May 31, 2026 at 2:05 pm

    Create a custom receiver like this

    class deliverReceiver extends BroadcastReceiver {     
    @Override
     public void onReceive(Context context, Intent arg1) {
                 switch (getResultCode())
                 {
                     case Activity.RESULT_OK:
                         Toast.makeText(getBaseContext(), "SMS delivered", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case Activity.RESULT_CANCELED:
                         Toast.makeText(getBaseContext(), "SMS not delivered", 
                                 Toast.LENGTH_SHORT).show();
                         break;                        
                 }
    
             }
    }
    

    and a sent reciever like this..

    class sentReceiver extends BroadcastReceiver {     
    @Override
     public void onReceive(Context context, Intent arg1) {
                 switch (getResultCode())
                 {
                     case Activity.RESULT_OK:
                         Toast.makeText(getBaseContext(), "SMS sent", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                         Toast.makeText(getBaseContext(), "Generic failure", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case SmsManager.RESULT_ERROR_NO_SERVICE:
                         Toast.makeText(getBaseContext(), "No service", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case SmsManager.RESULT_ERROR_NULL_PDU:
                         Toast.makeText(getBaseContext(), "Null PDU", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                     case SmsManager.RESULT_ERROR_RADIO_OFF:
                         Toast.makeText(getBaseContext(), "Radio off", 
                                 Toast.LENGTH_SHORT).show();
                         break;
                 }
    
    
             }
    

    now in sendSMS method after this

     PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
             new Intent(DELIVERED), 0);
    

    put

    registerReceiver(sentReceiver,SENT);
    registerReceiver(deliverReceiver,DELIVERED);
    

    Now override onpause and unregister for the receivers like this..

    unregisterReceiver(sentReceiver);
    unregisterReceiver(deliverReceiver);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send a sms with smslib but It did not send
I am trying to send and receive SMS via kannel. I have set everything,
I'm trying to send and receive binary data sms from my app (sdk 2.1-update
I am trying to send SMS using php's mail() function. Below you will find
I was trying to send SMS from within my app. I wrote this piece
I`m trying to send e-mail via c# and use the following code: public static
I'm trying to send a byte[] (using PUT) with Restlet but I can't find
I am trying to send an SMS on an iPhone using MFMessageComposeVieController and I
I'm trying to send a sms via a Nokia phone over serial which is
I am trying to access and send SMS through Wavecom's FXT-009 using Serial Port

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.