【发布时间】:2026-01-09 22:10:01
【问题描述】:
我正在使用以下代码从 Firebase 存储下载文件:
[来源:https://firebase.google.com/docs/storage/android/download-files]
islandRef = storageRef.child("images/island.jpg");
File localFile = File.createTempFile("images", "jpg");
islandRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
// Local temp file has been created
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
但是,我注意到 Firebase 在没有互联网的情况下会不断重试。
这就是为什么我也尝试过:
mStoragePath.setMaxDownloadRetryTimeMillis(60000);
mStoragePath.setMaxOperationRetryTimeMillis(60000);
mStoragePath.setMaxUploadRetryTimeMillis(60000);
但这只是设置最大超时值。是否有可能一次尝试失败。
谢谢。
【问题讨论】:
-
为什么你希望它在第一次尝试后失败?可能的解决方案可能是检查您是否有网络连接并对其做出反应。
标签: android firebase firebase-storage