。その後、
public Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
URLConnection connection = (URLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(input);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
String filename;
Date date = new Date(0);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
filename = sdf.format(n);
File myDir=new File("/sdcard/Pictures");
myDir.mkdirs();
String fname = "Image-"+ n +".jpg";
// filename = sdf.format(date);
File file = new File(myDir, fname);
if (file.exists()) file.delete();
try {
file.createNewFile();
FileOutputStream fo = new FileOutputStream(file);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
Toast.makeText(getApplicationContext(),"Saved to Light Box",Toast.LENGTH_LONG).show();
// 5
fo.write(bytes.toByteArray());
fo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}