簡體   English   中英

從 Firebase 下載文件 | 應用程序在調試但不是發布模式下工作

[英]Downloading files from Firebase | App works in debug but not release mode

我正在嘗試下載名為 1.pdf、2.pdf 的 Firebase 存儲目錄中的所有文件......代碼在調試模式下工作,但在發布中不起作用。 我一整天都被困在這個問題上。 我認為它可能是從另一個班級開始的,但老實說我不知道​​。

從 Firebase 獲取文件的代碼:

   for (int i = 1; i < 10000; i++) {
        StorageReference ref = storageRef.child("FirstTimeForms/" + i + ".pdf");
        File localFile = File.createTempFile("Form", ".pdf");
        FileDownloadTask dm = ref.getFile(localFile);
        int fileSize = Integer.parseInt(String.valueOf(localFile.length()/1024));

        if(fileSize > 0){
            fileManager.copyFile(localFile, new File("/sdcard/Download/Forms/" + i + ".pdf"));
        }else{
            return;
        }
    }

將從緩存下載的文件復制到 SD 的代碼

  FileChannel inChannel = new FileInputStream(src).getChannel();
        FileChannel outChannel = new FileOutputStream(dst).getChannel();
        try
        {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        }
        finally
        {
            if (inChannel != null)
                inChannel.close();
            if (outChannel != null)
                outChannel.close();
        }

在您的 proguard-rules.pro 中添加這些

-keep class com.firebase.** { *; }
-keepattributes *Annotation*
-keepattributes Signature

-keep class YOUR_PACKAGE_NAME.YourActivity { *; }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM