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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:29:29+00:00 2026-06-18T16:29:29+00:00

I have created like get parameter in php And I am using Get method

  • 0

I have created like get parameter in php And I am using Get method to submit to the link. For eg: “http://example.com/subscribe/?act=SubscribeForEmail&EmailAddress=” .

if user type in edittext(say aa@gmail.com) and submit, it will submit as

http://example.com/subscribe/?act=SubscribeForEmail&EmailAddress=aa@gmail.com. How it’s

possible in android?

I tried by using this by an example. But it force closes

The code is as follows:

EditText Ename;
Button btncreate;
String n = null;
String contentOfMyInputStream1;
String output = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Ename = (EditText)findViewById(R.id.msgTextField);
    btncreate = (Button)findViewById(R.id.sendButton);
    btncreate.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onClick(View v) {   
    String st1;
    st1 = Ename.getText().toString();
    try {
        output = "http://example.com/subscribe/?act=SubscribeForEmail&EmailAddress="+st1;
        downloadUrl(output);//request been send
    } 
    catch (IOException e) {
        e.printStackTrace();
    }
    if (output != null) {
        Toast.makeText(this, output, Toast.LENGTH_SHORT).show();
    }
}

public String downloadUrl(String url) throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpRequestBase httpRequest = null;
    HttpResponse httpResponse = null;
    InputStream inputStream = null;
    String response = "";
    StringBuffer buffer = new StringBuffer();
    httpRequest = new HttpGet(url); 
    httpResponse = httpclient.execute(httpRequest);
    inputStream = httpResponse.getEntity().getContent();
    int contentLength = (int) httpResponse.getEntity().getContentLength();
    if (contentLength < 0)  {
        // Log.e(TAG, "The HTTP response is too long.");
    }
    byte[] data = new byte[256];
    int len = 0;
    while (-1 != (len = inputStream.read(data)) ) {
        buffer.append(new String(data, 0, len));
    }
    inputStream.close();
    response = buffer.toString();
    return response;
}

I am getting error as

Fatal Exception:main
android.os.NetworkOnMainTreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
at java.net.InetAddress.lookHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:385)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)

Please help me to solve the issue.

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-18T16:29:30+00:00Added an answer on June 18, 2026 at 4:29 pm

    As simple as the Exception tells you. You run network stuff on the main Thread. Use AsyncTask or a new Thread to execute your downloadUrl method.

    Use this example code, taken from here:

    private class LongOperation extends AsyncTask<String, Void, String> {
    
          @Override
          protected String doInBackground(String... params) {
                //Here you put your downloadUrl() method.
                //because this method does stuff in background
                return downloadUrl(params[0])
          }      
    
          @Override
          protected void onPostExecute(String output) {
              //after downloading is finished, toast it.
              if (output != null)
                  Toast.makeText(this, output, Toast.LENGTH_SHORT).show();
          }
    
          @Override
          protected void onPreExecute() {
          }
    
          @Override
          protected void onProgressUpdate(Void... values) {
          }
    }   
    

    Call it by these two lines:

    LongOperation downloadTask = new LongOperation();
    downloadTask.execute(output);
    

    This site might help as well.

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

Sidebar

Related Questions

Okay.. so basically, say we have a link: $url = http://www.site.com/index.php?sub=Mawson&state=QLD&cat=4&page=2&sort=z; Basically, I need
I have created Controller Attribute and would like to read SessionId but get error
I'm using MVC 1.0 and have created a RequireSSLAttribute (like the one in ASP.NET
I am using the new System.Web.Optimization and have created a bundle like this: bundles.Add(New
I created a pagination by roughly following this link: http://www.awcore.com/dev/1/3/Create-Awesome-PHPMYSQL-Pagination_en#toggle quite cool. Although I
In PHP, I have created a user defined function. Example: <?php function test($one, $two)
Using Symfony I created a form in the backend. I have a submit button,
I have created like a design studio and it has different functionalities like drag
I have created something like this and this . In effect I have a
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',

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.