You can't do network operations on the main UI thread. What you will have to do is create a new Thread and do the network stuff there. If you need to, you can then you can post updates back to the main UI thread using a Handler. If you need a code sample, I can post a minimal one that should work.
It's important when you do this NOT to maintain a strong reference back to the Activity or you can leak the whole activity on a device rotate or other onDestroy() event. Because you're passing the Context out to a different thread, you'll want to test this to make sure you're not leaking. I wrote a blog post about this on my Tumblr:
Edit 1
Here's some code that should help:
static final class ProgressMessages extends Handler
{
private WeakReference<MyAndroidClass> weakAndroidClassRef;
public ProgressMessages (MyAndroidClass myContext)
{
weakWritingPadRef = new WeakReference<MyAndroidClass>( myContext);
}
public void handleMessage(Message msg)
{
String s = "Uploading page " + msg.arg1 + ".";
Toast t = Toast.makeText(weakAndroidClassRef.get(), s, Toast.LENGTH_LONG);
t.show();
}
};
ProgressMessages pm;
public void doNetworkStuff()
{
t = new Thread()
{
public void run()
{
Looper.prepare();
try
{
pm.sendMessage(Message.obtain(pm, 0, i + 1, 0));
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
pm.post(update);
}
};
t.start();
}