Q:

How to avoid android.os.NetworkOnMainThreadException

I am trying to send a picture to my local web server from my android phone. Once it connects to the web server I get the following: android.os.NetworkOnMainThreadException
I think that the solution to my problem is to make the method async. This is something I am not familiar with.
So my question is:
How can I make the following method async?
public class Send {
    public Send(){
    }

public static String send(String path) throws Exception {
    String filePath = path;
    String svar;

    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpPost httppost = new HttpPost("path to web server"); 
        FileBody pic = new FileBody(new File(filePath)); 
        MultipartEntity requestEntity = new MultipartEntity(); 
        requestEntity.addPart("file", pic);

        httppost.setEntity(requestEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity responseEntity = response.getEntity();
        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());

        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        response.getEntity().writeTo(outstream);
        byte [] responseBody = outstream.toByteArray();
        svar = new String(responseBody);
        System.out.println(svar);

    } finally {
        try {
            httpclient.getConnectionManager().shutdown();
        } 
        catch (Exception ignore) {
      }
    }
    return svar;
  }

}

A:

Blocking operations cannot be performed on the main thread, as this would give poor user experience.
An AsyncTask is not hard to work out. The doInBackground method runs on another thread. The onPostExecute method allows you to update the UI, as this method runs on the main thread. Updating the UI is not allowed from any other threads.

