我能够下载图像,但不能在进度栏上显示下载进度。我正在从 Firebase数据库中检索图像。
我正在使用 Glide 库显示和下载图像。
下面是我用来下载图像的代码:
Glide.with(ViewActivity.this)
.asBitmap()
.load(getIntent().getStringExtra("image"))
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
saveImage(resource);
}
private String saveImage(Bitmap resource) {
String savedImagePath = null;
String fileName = title + ".jpg";
//String imageFileName = "JPEG_" + "FILE_NAME" + ".jpg";
File storageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
+ "/WideWallz");
boolean success = true;
if (!storageDir.exists()) {
success = storageDir.mkdirs();
}
if (success) {
File imageFile = new File(storageDir, fileName);
savedImagePath = imageFile.getAbsolutePath();
try {
OutputStream fOut = new FileOutputStream(imageFile);
resource.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.close();
} catch (Exception e) {
e.printStackTrace();
}
// Add the image to the system gallery
galleryAddPic(savedImagePath);
Toast.makeText(getApplicationContext(), "Wallpaper saved to Gallery", Toast.LENGTH_LONG).show();
downloadProgress.setVisibility(View.GONE);
downloadWallpaperSmall.setVisibility(View.GONE);
check.setVisibility(View.VISIBLE);
}
return savedImagePath;
}
private void galleryAddPic(String imagePath) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(imagePath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
sendBroadcast(mediaScanIntent);
}
});