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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:49:30+00:00 2026-05-31T10:49:30+00:00

I written following code to send sms. private void sendSMS(String phoneNumber) { String SENT

  • 0

I written following code to send sms.

private void sendSMS(String phoneNumber)
{        
    String SENT = "SMS_SENT";
    String DELIVERED = "SMS_DELIVERED";
    final AlertDialog dialog = new AlertDialog.Builder(this).create();

    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:
                dialog.setMessage("SMS is Successfully Sent for Contact Request ");
                dialog.setTitle("ALERT:SMS Sent");

                dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",
                new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    return;

                }
                });
                dialog.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;
          }
         return;
     }
  }, new IntentFilter(SENT));


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, messageToSend, sentPI, deliveredPI);      
}

The code is running successfully in Emulator but not in phone.
It shows the following error

            case SmsManager.RESULT_ERROR_NO_SERVICE:
            Toast.makeText(getBaseContext(), "No service",);

I have given the required permissions and have SIM(with enough balance) in the phone as well.

  • 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-31T10:49:31+00:00Added an answer on May 31, 2026 at 10:49 am

    use this piece of code for sending message

    private void sendSMS(String phoneNumber, String message)
    {        
        Log.d("phoneNumber",phoneNumber);
        Log.d("MEssage",message);
        PendingIntent pi = PendingIntent.getActivity(CONTEXT, 0,
            new Intent(CONTEXT,Object.class), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written the following code to (successfully) connect to a socks5 proxy. I send
I've written the following code: public static void BeginListen( int port ) { IPAddress
I have written a following code to get just the file name without extension
I have written the following code choice /m Do you want to add another
I've written the following code to create a three-column layout where the first and
I have written the following code. But it is removing only &nbsp; not <br>
i have written the following code: As you can see there is a for
I have written the following IronPython code: import clr clr.AddReference(System.Drawing) from System import *
In physics library written in C# I have the following code: (in ContactManager.cs) public
I'm trying to use the following code (poorly written, but it's just a proof

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.