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

  • Home
  • SEARCH
  • 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 8733797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:43:23+00:00 2026-06-13T09:43:23+00:00

I want to make an app for sending sms.I am using following code for

  • 0

I want to make an app for sending sms.I am using following code for that purpose.But i am getting Some BroadCastReceiver exception.This is the code:

  public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sendsmslayout);        
        btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
        txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
        txtMessage = (EditText) findViewById(R.id.txtMessage);

        /*
        Intent sendIntent = new Intent(Intent.ACTION_VIEW);
        sendIntent.putExtra("sms_body", "Content of the SMS goes here..."); 
        sendIntent.setType("vnd.android-dir/mms-sms");
        startActivity(sendIntent);
        */

        btnSendSMS.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {               
                String phoneNo = txtPhoneNo.getText().toString();
                String message = txtMessage.getText().toString();               
                if (phoneNo.length()>0 && message.length()>0)                
                    sendSMS(phoneNo, message);                
                else
                    Toast.makeText(getBaseContext(), 
                        "Please enter both phone number and message.", 
                        Toast.LENGTH_SHORT).show();
            }
        });        
    }

    //---sends a SMS message to another device---
    private void sendSMS(String phoneNumber, String message)
    {      
        /*
        PendingIntent pi = PendingIntent.getActivity(this, 0,
                new Intent(this, test.class), 0);                
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phoneNumber, null, message, pi, null);        
        */

        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(){
            @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(){
            @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);               
    }    

This is the exception:

10-22 12:38:37.461: E/ActivityThread(1219): Activity org.secure.sms.SendSMS has leaked IntentReceiver org.secure.sms.SendSMS$3@44e98630 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-22 12:38:37.461: E/ActivityThread(1219): android.app.IntentReceiverLeaked: Activity org.secure.sms.SendSMS has leaked IntentReceiver org.secure.sms.SendSMS$3@44e98630 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-22 12:38:37.461: E/ActivityThread(1219):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:797)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:608)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.app.ApplicationContext.registerReceiverInternal(ApplicationContext.java:724)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:711)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:705)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:308)
10-22 12:38:37.461: E/ActivityThread(1219):     at org.secure.sms.SendSMS.sendSMS(SendSMS.java:105)
10-22 12:38:37.461: E/ActivityThread(1219):     at org.secure.sms.SendSMS.access$0(SendSMS.java:56)
10-22 12:38:37.461: E/ActivityThread(1219):     at org.secure.sms.SendSMS$1.onClick(SendSMS.java:46)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.view.View.performClick(View.java:2364)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.view.View.onTouchEvent(View.java:4179)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.widget.TextView.onTouchEvent(TextView.java:6540)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.view.View.dispatchTouchEvent(View.java:3709)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-22 12:38:37.461: E/ActivityThread(1219):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
10-22 12:38:37.461: E/ActivityThread(1219):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
10-22 12:38:37.461: E/ActivityThread(1219):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.os.Looper.loop(Looper.java:123)
10-22 12:38:37.461: E/ActivityThread(1219):     at android.app.ActivityThread.main(ActivityThread.java:4363)
10-22 12:38:37.461: E/ActivityThread(1219):     at java.lang.reflect.Method.invokeNative(Native Method)
10-22 12:38:37.461: E/ActivityThread(1219):     at java.lang.reflect.Method.invoke(Method.java:521)
10-22 12:38:37.461: E/ActivityThread(1219):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-22 12:38:37.461: E/ActivityThread(1219):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-22 12:38:37.461: E/ActivityThread(1219):     at dalvik.system.NativeStart.main(Native Method)

Please help me.Thanks in advance.

  • 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-13T09:43:23+00:00Added an answer on June 13, 2026 at 9:43 am

    Define BroadcastReceiver outside of your sendSMS method (as global object). Then in onPause of your Activity, call unregisterReceiver to unregister the listener.

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

Sidebar

Related Questions

I want to make an app that has a view that moves randomly or
I want to make an app that can receive broadcast when other apps on
I want to make an Android app by using ZXing . Can anyone tell
i want to make a php app that let people submit photos/videos/sounds Now, everything
I want to make a iPhone app but I need to now how you
I am using MFMailComposeViewController for sending feedback in my app. It works fine. But
I am new android app developer i want make app for tablets and phone
I want to make an App Engine connected Android app, and I'm beginning with
i want to make an app which can add the file properties of a
HI all I want to make one app for iPhone 2.2.* and for version

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.