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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:52:38+00:00 2026-06-10T19:52:38+00:00

I am creating an app that takes String’s input by the user via EditText,

  • 0

I am creating an app that takes String’s input by the user via EditText, puts them into a sharedpreference and then sends an automatic sms when an sms is received, using the strings from the sharedpreference to dictate the phone number and text message that will be automatically sent.

The app works perfectly as long as I hardcode the phone number and the text message to be sent. As soon as I try and put the Strings from the shared preferences into the SendSMS method then the app crashes and I get a debug error “hasUserDataHeader : false”

The below code is the version where i try to take the String from the Name EditText and use it as the message to be sent via the parameter TextMessage (see within the broadcast receiver for this line of code). If i were to replace this with “TextMessage” then it would be fine but obviously this doesn’t make the text sent dynamic

Code below:

                import android.os.Bundle;
            import android.app.Activity;
            import android.view.Menu;
            import android.view.View;
            import android.widget.AdapterView;
            import android.widget.AdapterView.OnItemSelectedListener;
            import android.widget.ArrayAdapter;
            import android.widget.EditText;
            import android.widget.Spinner;
            import android.widget.Button;
            import android.app.PendingIntent;
            import android.content.Intent;
            import android.telephony.SmsManager;
            import android.content.BroadcastReceiver;
            import android.content.Context;
            import android.content.IntentFilter;
            import android.widget.TextView;
            import android.app.Notification;
            import android.app.NotificationManager;
            import android.content.SharedPreferences;

            public class MainActivity extends Activity {

                int notificationID = 1;
                String[] excuses;
                String excuseSelected;
                IntentFilter intentFilter;
                private SharedPreferences prefs;
                private String prefName = "MyPref";
                private static final String NUMBER_KEY = "number";
                private static final String NAME_KEY = "name";
                private static final String EXCUSE_KEY = "excuse"; 


                private BroadcastReceiver intentReceiver = new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {

                        //---gather up all the necessary user input---
                        prefs = getSharedPreferences(prefName, MODE_PRIVATE);
                        String textMessage = (String) prefs.getString(NAME_KEY, "");
                        sendSMS("0403579838", textMessage);             
            //          }
                    }
                };

                @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_main);

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

                    final Button btn1 = (Button)findViewById(R.id.buttonToggle);

                    excuses = getResources().getStringArray(R.array.excuses_array);
                    Spinner s1 = (Spinner) findViewById(R.id.spinnerExcuse);
                    final EditText EditTextNumber = (EditText) findViewById(R.id.editTextNumber);
                    final EditText EditTextName = (EditText) findViewById(R.id.editTextName);



                        //---Sorting the spinner view out for excuses selection---
                        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                                android.R.layout.simple_spinner_item, excuses);

                        s1.setAdapter(adapter);
                        s1.setOnItemSelectedListener(new OnItemSelectedListener()
                        {
                            public void onItemSelected(AdapterView<?> arg0, View arg1,
                                    int arg2, long arg3)
                            {
                                int index = arg0.getSelectedItemPosition();
                                excuseSelected = excuses[index];
                            }

                            public void onNothingSelected(AdapterView<?> arg0) {}
                        });

                    //---Setting the button to toggle between on and off---
                    btn1.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            if (btn1.getText().equals("Turn on"))                       
                            {
                                btn1.setText("Turn off");
                                //---register the receiver---
                                registerReceiver(intentReceiver, intentFilter);
                                //---get the SharedPreferences object---
                                prefs = getSharedPreferences(prefName, MODE_PRIVATE);
                                SharedPreferences.Editor editor = prefs.edit();

                                //---set the user inputs to prefo's---
                                editor.putString(NUMBER_KEY, EditTextNumber.getText().toString());
                                editor.putString(NAME_KEY, EditTextName.getText().toString());
                                editor.putString(EXCUSE_KEY, excuseSelected);

                            }
                            else
                            {
                                btn1.setText("Turn on");
                                //---unregister the receiver---
                                unregisterReceiver(intentReceiver);
                            }
                        }
                    });

                }

                //---sends an SMS message to another device---
                public void sendSMS(String phoneNumber, String message)
                {
                    SmsManager sms = SmsManager.getDefault();
                    sms.sendTextMessage(phoneNumber, null, message, null, null);
                    displayNotification();
                }

                protected void displayNotification()
                {
                    Intent i = new Intent(this, NotificationView.class);
                    i.putExtra("notificationID", notificationID);

                    PendingIntent pendingIntent =
                        PendingIntent.getActivity(this, 0, i, 0);

                    NotificationManager nm = (NotificationManager)
                        getSystemService(NOTIFICATION_SERVICE);

                    Notification notif = new Notification(
                            R.drawable.ic_launcher,
                            "SMS has been sent by GirlfriendMinder",
                            System.currentTimeMillis());

                    CharSequence from = "GirlfriendMinder";
                    CharSequence message = "SMS has been sent by GirlfriendMinder";

                    notif.setLatestEventInfo(this, from, message, pendingIntent);

                    //---100ms delay, vibrate for 250ms, pause for 100ms, and then vibrate for 500ms---
                    notif.vibrate = new long[] { 100, 250, 100, 500};
                    nm.notify(notificationID, notif);
                }

                @Override
                protected void onDestroy() {
                    //---unregister the receiver---
                    unregisterReceiver(intentReceiver);
                    super.onPause();
                }
            }
  • 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-10T19:52:40+00:00Added an answer on June 10, 2026 at 7:52 pm

    In your code:

    //---Setting the button to toggle between on and off---
                        btn1.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                if (btn1.getText().equals("Turn on"))                       
                                {
                                    btn1.setText("Turn off");
                                    //---register the receiver---
                                    registerReceiver(intentReceiver, intentFilter);
                                    //---get the SharedPreferences object---
                                    prefs = getSharedPreferences(prefName, MODE_PRIVATE);
                                    SharedPreferences.Editor editor = prefs.edit();
    
                                    //---set the user inputs to prefo's---
                                    editor.putString(NUMBER_KEY, EditTextNumber.getText().toString());
                                    editor.putString(NAME_KEY, EditTextName.getText().toString());
                                    editor.putString(EXCUSE_KEY, excuseSelected);
    
                                }
                                else
                                {
                                    btn1.setText("Turn on");
                                    //---unregister the receiver---
                                    unregisterReceiver(intentReceiver);
                                }
                            }
                        });
    
                    }
    

    below:

    editor.putString(EXCUSE_KEY, excuseSelected);
    

    add

    editor.commit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an app that alerts user if he has been stationary for
I'm creating a webpy app that has multiple forms that take input and than
I am creating a mobile game that takes words from users and then validates
I am creating an app that takes information from a plist to create an
I'm planning on creating an app that takes data from an iPhone and sends
I'm creating an app that lets users take and store photos in a Core
I am creating an app that will point a simple arrow in the direction
I am creating an app that is a ticket sales system. On the checkout
I am creating an app that allows users to create and apply for jobs.
I'm creating an app that should list the date and time when a button

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.