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.

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

with the setEntity do i get the url like mailScript?id=12345&stringdata=AndDev_Is_Cool! ??
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.