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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:49:55+00:00 2026-06-11T23:49:55+00:00

my application is where user sends a well-wishing message. It has Spinner which contains

  • 0

my application is where user sends a well-wishing message. It has Spinner which contains the recipents’ names and they’re hardcoded. I’ve created a Toast message says”SMS is sent successfully”. but I realize I need to include a certain recipent’s name in the Toast message to confirm that the message is sent to the recipent.

I’ve tried whatever Toast messages I know to try to include the recipent’s name but I get errors and the Toast message failed when I run the app. I’ll post the full codes of the SMS app.

public class SMSEvents extends Activity
{
    Button btnSMS;
    EditText messageTxt;
    IntentFilter intentFilter;
    TextView text, textName;
    Spinner sendTo;

    ArrayAdapter<String> adapter;
    String friends[] = {"Kanak Priya", "Joanne Liew", "Melissa Haiting", "Michelle Lam", "Teo Kin Hua", "David Yeo", "Nur Ashiqin", "Stephanie"};

    private int namesSpinnderId;

    private BroadcastReceiver intentReceiver = new BroadcastReceiver()
        {
            @Override
            public void onReceive(Context context, Intent intent)
            {
                // ---display the SMS received in the TextView---
                TextView text = (TextView) findViewById(R.id.text);
                text.setText(intent.getExtras().getString("sms"));                          
            }                       
    };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sms);

        sendTo = (Spinner) findViewById(R.id.sendTo);

        adapter = new ArrayAdapter<String>(this,
                R.layout.spinner_text, friends);
        sendTo.setAdapter(adapter);





        /*BuddyDBAdapter buddyDB = new BuddyDBAdapter(this);

        sendTo = (Spinner) findViewById(R.id.sendTo);
        Cursor friendsCursor = buddyDB.getAllNames();
        startManagingCursor(friendsCursor);*/

        /*String[] from = new String[]{BuddyDBAdapter.KEY_NAME};
        int[] to = new int[]{R.id.sendTo};

        SimpleCursorAdapter friendsAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, friendsCursor, from, to);
        friendsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sendTo.setAdapter(friendsAdapter);*/

       /* sendTo.setOnItemSelectedListener(new OnItemSelectedListener()
            {

                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
                {
                    Cursor c = (Cursor)parent.getItemAtPosition(pos);
                    namesSpinnderId = c.getInt(c.getColumnIndexOrThrow(BuddyDBAdapter.KEY_ROWID));                  
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0)
                {
                    // TODO Auto-generated method stub

                }

            });*/

        // ---intent to filter for SMS messages received---
        intentFilter = new IntentFilter();
        intentFilter.addAction("SMS_RECEIVED_ACTION");

        // ---register the receiver---
        registerReceiver(intentReceiver, intentFilter);

        //sendTo = (EditText) findViewById(R.id.sendTo);
        //textName = (TextView) findViewById(R.id.textName);


        sendTo = (Spinner) findViewById(R.id.sendTo);
        messageTxt = (EditText) findViewById(R.id.messageTxt);

        btnSMS = (Button) findViewById(R.id.btnSMS);
        btnSMS.setOnClickListener(new View.OnClickListener()
            {
                public void onClick(View v)
                {
                    String contact_name = sendTo.getSelectedItem().toString();
                    String message = messageTxt.getText().toString();

                    if (contact_name.length() > 0 && message.length() > 0)
                        sendSMS(contact_name, message);
                    else
                        Toast.makeText(
                                getBaseContext(),
                                "Please enter your message",
                                Toast.LENGTH_SHORT).show();

                    /*Intent msgIntent = new Intent(android.content.Intent.ACTION_VIEW);
                    msgIntent.putExtra("sms_body", "default content");
                    msgIntent.setType("vnd.android-dir/mms-sms");
                    startActivity(msgIntent);*/
                }

            });

        Button btnBack = (Button) findViewById(R.id.btnMain);
        btnBack.setOnClickListener(new View.OnClickListener()
            {

                @Override
                public void onClick(View arg0)
                {
                    Intent menuIntent = new Intent(SMSEvents.this, MainPage.class);
                    startActivity(menuIntent);

                }
            });


    }




    @Override
    protected void onResume()
    {
        // ---register the receiver---
        // registerReceiver(intentReceiver, intentFilter);
        super.onResume();
    }

    @Override
    protected void onPause()
    {
        // ---unregister the receiver---
        // unregisterReceiver(intentReceiver);
        super.onPause();
    }

    @Override
    protected void onDestroy()
    {
        // ---unregister the receiver---
        unregisterReceiver(intentReceiver);
        super.onPause();
    }

    private void sendSMS(String contact_name, 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()
            {
                @Override
                public void onReceive(Context arg0, Intent arg1)
                {
                    switch (getResultCode())
                        {
                        case Activity.RESULT_OK:
                            Toast.makeText(getBaseContext(), "SMS is sent to" +contact_name successfully",
                                    Toast.LENGTH_SHORT).show();
                            break;

                        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                            Toast.makeText(getBaseContext(), "Service 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("5554", null, message, sentPI, deliveredPI);
        //sms.sendTextMessage(contact_name, null, message, sentPI, deliveredPI);

        /*try
        {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(contact_name, null, message, null, null);
            Toast.makeText(getApplicationContext(), "SMS is sent successfully!", Toast.LENGTH_LONG).show();
        }
        catch(Exception e)
        {
            Toast.makeText(getApplicationContext(), "SMS failed! Please try again later!", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }*/
    }
}

The Toast.makeText(getBaseContext(), "SMS is sent to" +contact_name successfully",
Toast.LENGTH_SHORT).show();
which I’m trying to do to include the recipent’s name.

If anyone knows how to do this Toast, I’ll appreciate it =). Sorry for asking a simple help but I tried 3 different ways of doing this kind of Toast message.

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-11T23:49:56+00:00Added an answer on June 11, 2026 at 11:49 pm

    I’ve figured out how to do this Toast.

    You code this Toast message in public void onReceive() which is within private void sendSMS()

    like this:

    Toast.makeText(getBaseContext(), "SMS is sent to " +sendTo.getSelectedItem()+ " successfully.",
    Toast.LENGTH_SHORT).show();

    The getSelectedItem() is getting selected item from Spinner. IF you’re using EditText or TextView, just replace getSelectedItem() with getText()

    :D, those whoever has similar problem to mine, can try this answer out and hope it solves their similar problems. 😀

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

Sidebar

Related Questions

My application sends Facebook notifications to a user. Is that possible to format the
I'm developing an application (user space) which send notifications of value changes via network.
I am making a messaging application in which user can send or receive a
I am trying to make a simple application which will send the user to
We have developed a messaging application in j2me which adds text message, gets pictures
i am making a application in which user enter a date when he want
I am writing a windows service which will communicate to a user level application.
Im working on a Client/server chat application which allows user to send files (images
Scenario: User A send application request to user B User B accepts request after
I'm working on an application that allows the user to send a file using

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.