gpt4 book ai didi

android - 我找不到从 firebase 下载到内部存储的文件

转载 作者:行者123 更新时间:2023-11-30 00:24:50 24 4
gpt4 key购买 nike

下面的代码工作得很好。它从 firebase 存储下载一个 pdf 文件并将其保存在设备的内部存储中。这里的问题似乎是我在 Android 设备监视器中找不到下载的文件。

btnDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String magazineUrl= magazineUri[0];

new Thread(new Runnable(){
@Override
public void run() {
try {

FirebaseStorage storage = FirebaseStorage.getInstance();
// Creating a reference to the link
StorageReference httpsReference = storage.getReferenceFromUrl(magazineUrl);

File file;
file=new File(mContext.getFilesDir(),"DownloadedMagazines.pdf");

httpsReference.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {

System.out.println("It has been downloaded");
// Local temp file has been created
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
System.out.println("It has failed to download");

}
});
}catch (final Exception e) {
System.out.println("Error : Please check your internet connection " + e);
}
}
}).start();


}
});

我的问题是,文件存储在哪里?有没有可能的方法来检索下载文件的路径?

最佳答案

您的文件存储在应用程序的私有(private)目录中。如果要将文件保存在公共(public)目录中,请使用:

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); // For example
File file = new File(path, "DownloadedMagazines.pdf");

您可以使用 Environment.DIRECTORY_DOWNLOADSEnvironment.DIRECTORY_DOCUMENTS 和其他...

注意,您需要 WRITE_EXTERNAL_STORAGE 权限,从 KITKAT 开始,读取权限需要 READ_EXTERNAL_STORAGE

关于android - 我找不到从 firebase 下载到内部存储的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45583090/

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