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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:19:00+00:00 2026-06-12T20:19:00+00:00

I am working on an Android sms application.The following code I used to send

  • 0

I am working on an Android sms application.The following code I used to send sms.

public void sendSms(final String phoneNumber, final 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 --

    sendBroadcastReceiver=new BroadcastReceiver() {


        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            switch (getResultCode()) {

                case Activity.RESULT_OK:

                    Toast.makeText(getBaseContext(), "SMS sent",
                        Toast.LENGTH_SHORT).show();

                    ContentValues values = new ContentValues();
                    values.put("address", phoneNumber);
                    values.put("body", message);
                    getContentResolver().insert(Uri.parse("content://sms/sent"), values);


                    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();

                    ContentValues values1 = new ContentValues();


                    values1.put("address", phoneNumber);
                    values1.put("body", message);
                    getContentResolver().insert(Uri.parse("content://sms/queued"), values1);

                    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;

                default:
                    break;
            }

            context.unregisterReceiver(this);
        }
    };

    SmsManager sms = SmsManager.getDefault();

        registerReceiver(sendBroadcastReceiver , new IntentFilter(SENT));
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);

}

It is working fine when I keep the screen until sms sent. It will write that sms to content/sms/sent or queued depends on sent report.But if i press back button while sending sms .it will send the sms but do not write to content/sms/sent or queued also won,t unregister broadcast too.

Please help me to solve my issue.

  • 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-12T20:19:01+00:00Added an answer on June 12, 2026 at 8:19 pm

    I had solved my problem by using service. Using startservice() and stopservice() I can manage registeration.Thanks for the suggestions friends.
    @Vikki…Your answer gave me the key.

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

Sidebar

Related Questions

I'm working on an SMS Application for Android, which undoubtedly needs to send SMSes
I am working on an android sms application.I have to send sms to multiple
I am working on an android sms application.I can send sms to single contact
I am working on an android application and I want to send an SMS
I am working on android chat application. I am facing a problem in send
I need a help in Android sms application. I am sending a message from
I am working on sms application in android in which user have to input
I am working on a android application which read the sms from content provider.
I am working with a SMS listener, code below: public class SMSReceiver extends BroadcastReceiver
I am working on an Android application.The app is like native sms application.I am

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.