0

Please how can I pass the contents of my android form data to a webpage and this data is displayed on the webpage.

In essence, when I click on the "ok" button of my android form data, I want the webpage to be opened with those data being displayed.

Thanks.

I am opening the webpage using the code snippet below

  public void onClick(View v) {
      Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://10.0.2.2/test/confirmPayment.php"));      
      new MyAsyncTask().execute(ntwk);
      startActivity(browserIntent);
  }

I'm trying to pass the form data using the code below.

  public class MyAsyncTask extends AsyncTask<String, Integer, Double>{

@Override
protected Double doInBackground(String... params) {
    // TODO Auto-generated method stub
    postData(params[0]);
    return null;
}

protected void onPostExecute(Double result){
    //pb.setVisibility(View.GONE);
    Toast.makeText(getApplicationContext(), "command sent", Toast.LENGTH_LONG).show();
}


private Context getApplicationContext() {
    // TODO Auto-generated method stub
    return null;
}

public void postData(String valueIWantToSend) {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://10.0.2.2/test/confirmPayment.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("names", valueIWantToSend));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

  }

The problem is that the webpage opens but the form data isn't passed. Please help. Thanks.

fidazik
  • 423
  • 1
  • 5
  • 11
  • What you tried? post it first – M D Mar 11 '14 at 12:55
  • @SimplePlan just did that – fidazik Mar 11 '14 at 13:05
  • Go to this: [http://stackoverflow.com/questions/16315415/how-send-data-to-website-by-using-android-app?rq=1](http://stackoverflow.com/questions/16315415/how-send-data-to-website-by-using-android-app?rq=1) – M D Mar 11 '14 at 13:08

1 Answers1

0

Start by fixing your getApplicationContext method. It returns null which is used by your Toast. Second, if I'm not mistaken you are opening a default browser and making an Http post to another connection which is completely different from your browser connection. What I recommend is that you open your form or what so ever in a web view and override the javascript methods so that you can post a data to that web view.

Barışcan Kayaoğlu
  • 1,294
  • 3
  • 14
  • 35