I just ran your code and it works great for me. The image was uploaded to the SD card.
To note, make sure these permissions are set in your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Here are the logs I received (note that I added a ProgressDialog ):
03-21 16:53:46.422 21017-21017/com.imagedownload.danielnugent.imagedownload D/Activity﹕ #1 setTransGradationModeColor false 03-21 16:53:56.211 21017-21017/com.imagedownload.danielnugent.imagedownload D/Activity﹕ #1 setTransGradationModeColor false 03-21 16:54:06.441 21017-21017/com.imagedownload.danielnugent.imagedownload I/System.out﹕ Starting download 03-21 16:54:06.441 21017-21017/com.imagedownload.danielnugent.imagedownload D/Dialog﹕ checkMirrorLinkEnabled returns : false 03-21 16:54:06.441 21017-21017/com.imagedownload.danielnugent.imagedownload D/Dialog﹕ showing allowed 03-21 16:54:06.461 21017-25126/com.imagedownload.danielnugent.imagedownload I/System.out﹕ Downloading 03-21 16:54:06.461 21017-21017/com.imagedownload.danielnugent.imagedownload D/Activity﹕ #1 setTransGradationModeColor false 03-21 16:54:06.481 21017-21017/com.imagedownload.danielnugent.imagedownload D/ProgressBar﹕ updateDrawableBounds: left = 0 03-21 16:54:06.481 21017-21017/com.imagedownload.danielnugent.imagedownload D/ProgressBar﹕ updateDrawableBounds: top = 0 03-21 16:54:06.491 21017-21017/com.imagedownload.danielnugent.imagedownload D/ProgressBar﹕ updateDrawableBounds: right = 144 03-21 16:54:06.491 21017-21017/com.imagedownload.danielnugent.imagedownload D/ProgressBar﹕ updateDrawableBounds: bottom = 144 03-21 16:54:11.596 21017-21017/com.imagedownload.danielnugent.imagedownload I/System.out﹕ Downloaded
Just in case, this will be useful, here is the full MainActivity.java code that worked for me. (url is a placeholder):
import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Environment; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; public class MainActivity extends ActionBarActivity { private ProgressDialog pDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new DownloadFileFromURL().execute("http://www.example.com/IMG.jpg"); } @Override public boolean onCreateOptionsMenu(Menu menu) {
source share