接收前端传给的url :
/**
*
* @param imgPath
* @param context
*/
public void loadImg(final String imgPath, final Context context) {
T.showShort("开始下载");
new Thread(new Runnable() {
@Override
public void run() {
try {
BitmapDrawable drawable = (BitmapDrawable) Glide.with(context)
.load(imgPath)
.submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get();
Bitmap bitmap = drawable.getBitmap();
String name = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".jpg";
File path = new File(Environment.getExternalStorageDirectory() + "/haha", "images");
File output = new File(path, name);
String imagePath = output.getPath();
if (!output.getParentFile().exists()) output.getParentFile().mkdirs();
File f = new File(imagePath);
OutputStream os = new FileOutputStream(f);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
os.close();
Uri uri = Uri.fromFile(f);
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
T.showShort("下载成功,请到相册中查看");
}
});
} catch (Exception e) {
}
}
}).start();
}