I am trying to create a very simple Image Downloading app. in which i want to download all images from this url to sd card: https://www.dropbox.com/sh/5be3kgehyg8uzh2/AAA-jYcy_21nLBwnZQ3TBFAea
this code works to load image in imageview:
package com.example.imagedownloadsample;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_download);
final ImageView img = (ImageView) (findViewById(R.id.imageView1));
// File file = new File(Environment.getExternalStorageDirectory(),
// "Android/data/com.usd.pop");
Picasso.with(getApplicationContext())
.load("http://8020.photos.jpgmag.com/3456318_294166_528c960558_m.jpg")
.into(img);
}
}
but when i tried like this to download image to sd card i end-up with unfortunatelly app stopped error:
package com.example.imagedownloadsample;
import java.io.File;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.ActionBarActivity;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_download);
//final ImageView img = (ImageView) (findViewById(R.id.imageView1));
File file = new File(Environment.getExternalStorageDirectory(),
"Android/data/com.usd.pop");
Picasso.with(getApplicationContext())
.load("http://8020.photos.jpgmag.com/3456318_294166_528c960558_m.jpg")
.into((Target) file);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…