gpt4 book ai didi

android - 设备上没有空间时如何处理异常

转载 作者:太空狗 更新时间:2023-10-29 13:52:16 26 4
gpt4 key购买 nike

我正在尝试从 firebase 存储中下载文件。如果设备空间不足,我应该在哪里处理异常?

下面是我的代码:

   if (isExternalStorageWritable()) {

File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), file.getFileName());

StorageReference ref = ((Jink) (context.getApplicationContext())).getFileStorageRef(file.getFileName());

ref.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {

@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
// downloaded successfully

}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// download fail

}
});


} else {
//could not write to external storage
Toast.makeText(context, context.getString(R.string.resume_download_fail), Toast.LENGTH_SHORT).show();
}

最佳答案

大概写入磁盘会失败,这意味着我们将捕获它并通过 OnFailureListener 使用通用 ERROR_UNKNOWN(根据 the docs )将其显示出来错误消息中嵌入了文件系统错误。

关于android - 设备上没有空间时如何处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45035451/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com