Tuesday, December 18, 2012

[android-developers] How i convert upload code to AsyncTask?

  
     How i convert this class code with AsyncTask method?

            public class SimpleHttpPut {
    public static void main(String urlt,int t) {
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(urlt);
        try {
          List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
          nameValuePairs.add(new BasicNameValuePair("temp",String.valueOf(t)));
          post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     
          HttpResponse response = client.execute(post);
          BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
          String line = "";
          while ((line = rd.readLine()) != null) {
            System.out.println(line);
          }

        } catch (IOException e) {
          e.printStackTrace();
        }
      }
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment