case
R.id.iv_btn_download_addActivity:
if
(!verifyPermissions()){
Toast.makeText(getApplicationContext(),
"권한이 없습니다!"
, Toast.LENGTH_SHORT).show();
}
else
{
String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath() +
"/"
+ getString(R.string.app_name) +
"/"
;
final
File dir =
new
File(dirPath);
String imageURL = photoDataArrayList.get(position).getFileName();
final
String fileName = imageURL.substring(imageURL.lastIndexOf(
'/'
) +
1
);
BitmapDrawable bitmapDrawable = (BitmapDrawable) photoView.getDrawable();
Bitmap bitmap = bitmapDrawable.getBitmap();
Glide.with(
this
).asBitmap()
.load(photoDataArrayList.get(position).getFileName())
.into(
new
CustomTarget<Bitmap>(
100
,
100
) {
@Override
public
void
onResourceReady(
@NonNull
Bitmap resource,
@Nullable
Transition<?
super
Bitmap> transition) {
saveImage(bitmap,dir,fileName);
}
@Override
public
void
onLoadCleared(
@Nullable
Drawable placeholder) {
}
@Override
public
void
onLoadFailed(
@Nullable
Drawable errorDrawable) {
super
.onLoadFailed(errorDrawable);
Toast.makeText(getApplicationContext(),
"다운로드 실패!"
, Toast.LENGTH_SHORT).show();
}
});
}
break
;
private
void
saveImage(Bitmap image, File storageDir, String imageFileName) {
boolean
successDirCreated =
false
;
if
(!storageDir.exists()) {
successDirCreated = storageDir.mkdir();
}
if
(successDirCreated) {
File imageFile =
new
File(storageDir, imageFileName);
String savedImagePath = imageFile.getAbsolutePath();
try
{
OutputStream fOut =
new
FileOutputStream(imageFile);
image.compress(Bitmap.CompressFormat.JPEG,
100
, fOut);
fOut.close();
Toast.makeText(getApplicationContext(),
"Image Saved!"
, Toast.LENGTH_SHORT).show();
}
catch
(Exception e) {
Toast.makeText(getApplicationContext(),
"Error while saving image!"
, Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
else
{
Toast.makeText(getApplicationContext(),
"Failed to make folder!"
, Toast.LENGTH_SHORT).show();
}
}
이렇게 했는데 안 됩니다. ㅠ
제가 현재 glide로 이미지 뷰에 뿌려주는건 내부 스토리지 경로로 뿌려주는데
저장하는건 bitmap 과 url로 저장해야 하더라구요 참고할만한 레퍼런스가 있을까요?