1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
public class UserActivity extends Activity
{
public static String mail;
public static String firstname ;
public static String phone ;
public static String lastname;
EditText edtmail;
EditText edtfirstname;
EditText edtlastname;
EditText edtphone;
Button btnEnvoyer;
InputStream is = null;
String result = null;
StringBuilder sb = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edtmail = (EditText) findViewById(R.id.userMail);
edtfirstname = (EditText) findViewById(R.id.userFirtName);
edtlastname = (EditText) findViewById(R.id.userLastName);
edtphone = (EditText) findViewById(R.id.userPhone);
btnEnvoyer = (Button) findViewById(R.id.btnEnvoyer);
btnEnvoyer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
envoyer();
}
});
}
public void envoyer() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.18:9000/usercreate");
mail = edtmail.getText().toString();
firstname = edtfirstname.getText().toString();
lastname = edtlastname.getText().toString();
phone = edtphone.getText().toString();
try {
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("email", mail));
nameValuePairs.add(new BasicNameValuePair("first_name", firstname));
nameValuePairs.add(new BasicNameValuePair("last_name", lastname));
nameValuePairs.add(new BasicNameValuePair("telephone", phone));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
/
Toast.makeText(this, "user create "+UserActivity.this.mail, Toast.LENGTH_SHORT).show();
} catch (ClientProtocolException e) {
Log.e("log_tag", "Error in http connection " + e.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
} |
Partager