How to download image file from Firebase storage To sd card

时间:2016-12-09 12:43:43

标签: android firebase firebase-storage

i am trying to download a image file form firebase storage. i want image to be stored in local sd card . i have stored my file island.jpg in my firebase stroage. But the code is not fleaching the file on to my sd card

 public void downloadpdf(){

        StorageReference  islandRef = mStorage.child("images/island.jpg");

        File localFile = null;

        try {
            localFile = File.createTempFile("images", "jpg");
        } catch (IOException e) {
            e.printStackTrace();
        }


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

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

when ever i call the above method i am able to print "kudos" so is this means i have downloaded my content ,but i am not able to find image on my sd card.

1 个答案:

答案 0 :(得分:1)

使用带有目录参数的createTempFile()形式并指定external files directory。然后打印文件的路径以查看它的创建位置:

try {
    localFile = File.createTempFile("images", "jpg", getExternalFilesDir(null));
} catch (IOException e) {
    e.printStackTrace();
}
System.out.println("localFile=" + localFile.getAbsolutePath());