지금은 지정된 url 로 이미지를 하나 받아오는데 여러개의 이미지를 받고싶습니다 어떤식으로해야될까요?
소스첨부
public class MainActivity extends Activity {
String imageUrl = "";
Bitmap mSaveBm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView bmImage = (ImageView) findViewById(R.id.image);
Button btnSave = (Button) findViewById(R.id.btnSave);
btnSave.setOnClickListener(btnSaveOnClickListener);
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
OpenHttpConnection opHttpCon = new OpenHttpConnection();
opHttpCon.execute(bmImage, imageUrl);
}
Button.OnClickListener btnSaveOnClickListener = new Button.OnClickListener() {
public void onClick(View arg0) {
OutputStream outStream = null;
String extStorageDirectory = Environment
.getExternalStorageDirectory().getAbsolutePath();
String fpath = extStorageDirectory + "/DCIM/Camera";
File file = new File(fpath, "123.jpg");
File file2 = new File(fpath, "456.jpg");
try {
Log.i("LSJ", "File Check:" + file.exists());
if (file.exists() == false) {
outStream = new FileOutputStream(file);
mSaveBm.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
Toast.makeText(MainActivity.this, "저장완료", Toast.LENGTH_LONG)
.show();
Log.i("LSJ", "File Check:" + "파일없어서 저장완료");
} else if (file.exists() == true) {
outStream = new FileOutputStream(file2);
mSaveBm.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
Toast.makeText(MainActivity.this, "파일이 중복되어 다른이름으로 저장", Toast.LENGTH_LONG)
.show();
Log.i("LSJ", "File Check:" + "파일 중복으로 다른이름저장");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, e.toString(),
Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, e.toString(),
Toast.LENGTH_LONG).show();
}
}
};
private class OpenHttpConnection extends AsyncTask<Object, Void, Bitmap> {
private ImageView bmImage;
@Override
protected Bitmap doInBackground(Object... params) {
Bitmap mBitmap = null;
bmImage = (ImageView) params[0];
String url = (String) params[1];
InputStream in = null;
try {
in = new java.net.URL(url).openStream();
mBitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return mBitmap;
}
@Override
protected void onPostExecute(Bitmap bm) {
super.onPostExecute(bm);
mSaveBm = bm;
bmImage.setImageBitmap(bm);
}
}
}