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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:16:29+00:00 2026-06-12T04:16:29+00:00

i have the following android code , i have an sms broadcast receiver in

  • 0

i have the following android code , i have an sms broadcast receiver in a service that waits for in coming sms, then on receiving it, it shows a toast, then it is supposed to make a get request to the specified url ,everything works as expected but the upload message action is not taking place, stumped here .

public class ReceiverContainer extends Service{

 public SMSreceiver mSMSreceiver;
 public IntentFilter mIntentFilter;

@Override
public void onCreate()
{
    super.onCreate();

    //SMS event receiver
    mSMSreceiver = new SMSreceiver();
    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
    registerReceiver(mSMSreceiver, mIntentFilter);
}

@Override
public void onDestroy()
{
    super.onDestroy();

    // Unregister the SMS receiver
    unregisterReceiver(mSMSreceiver);
    mSMSreceiver = null;
}

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

public class SMSreceiver extends BroadcastReceiver
{
     public void Action(Context context,Intent intent) throws ClientProtocolException, URISyntaxException, IOException
        {
         Bundle myBundle = intent.getExtras();
         SmsMessage [] messages = null;
         String strMessage = "";
         String msgFrom = "";
         String msgText = "";

         if (myBundle != null)
         {
             Object [] pdus = (Object[]) myBundle.get("pdus");
             messages = new SmsMessage[pdus.length];

             for (int i = 0; i < messages.length; i++)
             {
                 messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                 strMessage += "SMS From: " + messages[i].getOriginatingAddress();
                 msgFrom += messages[i].getOriginatingAddress();
                 strMessage += " : ";
                 strMessage += messages[i].getMessageBody();
                 msgText += messages[i].getMessageBody();
                 strMessage += "\n";
             }

             Toast.makeText(context, strMessage, Toast.LENGTH_SHORT).show();

             uploadMessage(context,msgFrom,msgText);

         }
        }

    @Override
    public void onReceive(Context context, Intent intent)
    {
            try {
                Action(context,intent);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }

}

public void uploadMessage(Context context,String number,String msg) throws URISyntaxException, ClientProtocolException, IOException
{

    HttpResponse response = null;
    HttpClient client = new DefaultHttpClient();


    Uri.Builder path = new Uri.Builder();
    path.scheme("http");
    path.authority("technonectar11.com");
    path.path("sms");
    path.appendQueryParameter("fromno" , number);
    path.appendQueryParameter("text" , msg);
    path.appendQueryParameter("uname" , "vijay");

    HttpGet request = new HttpGet(path.build().toString());     
    //request.setURI(new URI("http://www.technonectar11.com/sms/insertsms?fromno="+number+"&text="+msg+"&uname=vijay"));
    response = client.execute(request);

    String result = convertStreamToString(response.getEntity().getContent());

    Toast.makeText(context, result, Toast.LENGTH_SHORT).show();

}

public static String convertStreamToString(InputStream inputStream) throws IOException
{
    if (inputStream != null)
    {
        Writer writer = new StringWriter();

        char[] buffer = new char[1024];
        try
        {
            Reader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"),1024);
            int n;
            while ((n = reader.read(buffer)) != -1)
            {
                writer.write(buffer, 0, n);
            }
        }
        finally
        {
            inputStream.close();
        }
        return writer.toString();
    }
    else
    {
        return "";
    }
}

}

  • 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-12T04:16:30+00:00Added an answer on June 12, 2026 at 4:16 am

    You are not allowed to make internet requests on the main thread.
    Use AsyncTasks to make the request.

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

Sidebar

Related Questions

I have the following code for Android which works fine to play a sound
I have the following code running on my Android device. It works great and
I have created an ExpandableListView with the following code: <ExpandableListView android:id=@+id/android:list android:layout_width=wrap_content android:layout_height=0dp android:layout_marginTop=5dp
I'm currently making a SMS Application in Android, the following is a code snippet
Android:How to display images from the web in a ListView?I have the following code
I have the following code: import android.support.v4.app.FragmentActivity; import android.support.v4.app.Fragment; public void onCreate(Bundle savedInstanceState) {
I want to set UI based on android:layout_weight .I have following code structure <LinearLayout
I have the following code in my XML file: <LinearLayout android:layout_width=fill_parent android:layout_height=60dip android:layout_marginLeft=13dp android:layout_marginRight=13dp
I have the following code in resultlookup.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:id=@+id/layoutResultOuter
Im getting nullpointerexception for the following code: I have SMS of more than 160

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.