The answer was to put the async task in a runnable. I found out I couldn't try to load the async task outside of the main UI thread. Also the code below makes it wait until it finishes scanning.
private File scanMedia() {
// TODO Auto-generated method stub
MediaScannerConnection.scanFile(MainScreen.this,
new String[] { photo.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
fullPath = path;
scanned = true;
if(scanned){
new Thread()
{
public void run()
{
MainScreen.this.runOnUiThread(new Runnable()
{
public void run()
{
new PostPicture().execute();
}
});
}
}.start();
} else {
Log.e("Should scan","Didn't finish scanning");
}
}
});
return path;
}