I am a new android developer . I am building an app , in which a registration form is filled and its contents data is to be stored on the local host of mine . I have made the form but i don't know how to code for sending the data to local host. help me code from the basic so that WHEN A SEND BUTTON IS CLICKED , THE DATA FILLED IN THE FORM GETS STORED ON THE LOCAL HOST.
this is my code..................................
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity_server);
send1 = (Button)findViewById(R.id.Send);
send1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
testInput ti=new testInput();
//Create the intent
ti.postData("Sent Data");
TextView num1View = (TextView) findViewById(R.id.T5);
num1View.setText("your data is stored");
//Create the intent
}
});
}
public void postData(String toPost) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("my local host name");
//This is the data to send
String name = toPost;
String number= toPost;
String email =toPost;
String suggestion= toPost;//any data to send
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("action", name));
nameValuePairs.add(new BasicNameValuePair("action", number));
nameValuePairs.add(new BasicNameValuePair("action", email));
nameValuePairs.add(new BasicNameValuePair("action", suggestion));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);
//This is the response from a php application
String reverseString = response;
Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
// TODO Auto-generated catch block
} catch (IOException e) {
Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
// TODO Auto-generated catch block
}
}//end postData()