หน้าเว็บ

April 29, 2011

Test

   1: package example.JSON;
   2:  
   3: import java.io.IOException;
   4:  
   5: import org.apache.http.HttpResponse;
   6: import org.apache.http.client.ClientProtocolException;
   7: import org.apache.http.util.EntityUtils;
   8: import org.json.JSONException;
   9: import org.json.JSONObject;
  10:  
  11: import android.app.Activity;
  12: import android.os.Bundle;
  13: import android.widget.Toast;
  14:  
  15: public class JSON extends Activity
  16: {
  17:     /** Called when the activity is first created. */
  18:     @Override
  19:     public void onCreate(Bundle savedInstanceState)
  20:     {
  21:         JSONObject json = new JSONObject();
  22:         try
  23:         {
  24:             json.put("Longtude", "15");
  25:             json.put("Lattetude", "30");
  26:         }
  27:         catch (JSONException e)
  28:         {
  29:             // TODO Auto-generated catch block
  30:             e.printStackTrace();
  31:         }
  32:         String url = "http://www.upgardens.co.za/upload.php";
  33:         HttpResponse re;
  34:         String temp = new String();
  35:         try
  36:         {
  37:             re = HTTPPoster.doPost(url, json);
  38:             temp = EntityUtils.toString(re.getEntity());
  39:         }
  40:         catch (ClientProtocolException e)
  41:         {
  42:             // TODO Auto-generated catch block
  43:             e.printStackTrace();
  44:         }
  45:         catch (IOException e)
  46:         {
  47:             // TODO Auto-generated catch block
  48:             e.printStackTrace();
  49:         }
  50:         if (temp.compareTo("SUCCESS")==0)
  51:         {
  52:             Toast.makeText(this, "Sending complete!", Toast.LENGTH_LONG).show();
  53:         }
  54:         super.onCreate(savedInstanceState);
  55:         setContentView(R.layout.main);
  56:     }
  57: }

No comments:

Post a Comment