I followed your advice and here's my class to send a simple status .
public class SendStatus extends Activity implements OnClickListener{
EditText edit;
Button btn;
String status;
String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sendstatus);
url = "
https://api.empireavenue.com/profile/set/status/?
apikey=myapikey&username=ticker&password=password";
edit = (EditText)findViewById(R.id.send_status_edit_text);
btn = (Button)findViewById(R.id.send_status_btn);
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
status = edit.getText().toString();
Toast.makeText(getApplicationContext(), status,
Toast.LENGTH_LONG).show();
grabURL(url);
}
private class GrabURL extends AsyncTask<String, Void, Void> {
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();;
private ProgressDialog Dialog = new
ProgressDialog(SendStatus.this);
protected void onPreExecute() {
Dialog.setMessage("Sending status..");
Dialog.show();
}
protected Void doInBackground(String... urls) {
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new
UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
}catch(Exception e){
Log.e("log_tag", "Error in http connection
"+e.toString());
}
return null;
}
protected void onPostExecute(Void unused) {
Dialog.dismiss();
nameValuePairs.add(new BasicNameValuePair("status",status));
nameValuePairs.add(new BasicNameValuePair("username","ticker"));
nameValuePairs.add(new BasicNameValuePair("password","password"));
nameValuePairs.add(new BasicNameValuePair("apikey","myapikey"));
}
}
public void grabURL(String url){
new GrabURL().execute(url);
}
}
But it doesn't work . All the POST method is in the the
doInBackground, i don't know if you know some java but this is my
problem .