1

I'm neither a android or php expert, the thing is that I made a php script that gets the variables from the url ( www.myhost.com/mailScript.php?variable1=name&variable2=age ) and sends a mail with that information.

Mail:
Variable1=Name
Variable2=Age

Now, the problem is that i'm makin a android app that converts a normal form, which ask name, age, etc. And i want to take that information and run php script. But i dont want the users to see a web browser at any time, just that they click de button, get the info, run the url, and done.

Nanne
  • 61,952
  • 16
  • 112
  • 157
Raicerda
  • 15
  • 4

3 Answers3

3

The easiest way to do it is mentioned here. Basically, you just want to form the URL based on the value of each of your fields, then hit that URL with an HTTP request.

Community
  • 1
  • 1
Chris Cashwell
  • 20,898
  • 13
  • 60
  • 91
1

Use JSON to send data to your PHP script. By combining that

public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("id", "12345"));
        nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
        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
   }
}

Source : http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient

and looking about JSON, you should be able to do what you want

Jeremy D
  • 4,589
  • 1
  • 26
  • 36
0

your php will be the server side and your android application will the be the client side you will just create a form using normal android's UI widgets. There's a plenty of examples around and send your data via HttpPost or HttpGet classes with your parameters set from this form. http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-forms/ and posting example Secure HTTP Post in Android

Community
  • 1
  • 1
Sergey Benner
  • 4,313
  • 2
  • 22
  • 29