i want to sava data from android app to local host in my pc. i write a edittext to get my text:
<EditText
android:id="@+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
and write a method to send data to localhost:
public void send(View v3)
{
String msg = edittext2.getText().toString();
// make sure the fields are not empty
if (msg.length()>0)
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://localhost/datalog.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("message", msg));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
edittext2.setText(""); // clear text box
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
// Toast.makeText(getBaseContext(),"All field are required",Toast.LENGTH_SHORT).show();
}
}
else
{
// display message if text fields are empty
Toast.makeText(getBaseContext(),"All field are required",Toast.LENGTH_SHORT).show();
}
}
and call method by sendbutton:
sendButton = (Button) findViewById(R.id.sendButton);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v3) {
// TODO Auto-generated method stub
// send datasend=new send();
//datasend.execute();
send(v3);
}
});
but get a massage that: 08-10 01:14:26.171: V/InputMethodManager(20557): START INPUT: android.widget.EditText{41812b10 VFED..CL .F....ID 0,672-225,731 #7f080013 app:id/text2} ic=com.android.internal.widget.EditableInputConnection@418662b0 tba=android.view.inputmethod.EditorInfo@41866268 controlFlags=#100
i write a php code in server side ti get post variable.