首页 > 解决方案 > 从 Firebase 下载 Pdf 文件并更新进度条上的进度

问题描述

我正在从 Firebase 下载文件,文件正在完美下载,但我想在屏幕上下载文件时显示进度。我看过很多教程,但其中显示的方法要么已弃用,要么不起作用。请告诉我如何实现它。

public void download(){
        storageReference=firebaseStorage.getInstance().getReference();
        ref=storageReference.child("fileName.pdf");
        ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                String url=uri.toString();
                downloadPdf(className.this,"fileName",".pdf",DIRECTORY_DOWNLOADS,url);
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {

            }
        });

    }

    public void downloadPdf(Context context, String fileName, String fileExtensions, String destinationDirectory, String url){
        DownloadManager downloadManager= (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
        Uri uri=Uri.parse(url);
        DownloadManager.Request request=new DownloadManager.Request(uri);
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        request.setDestinationInExternalFilesDir(context, destinationDirectory, fileName+fileExtensions);
        downloadManager.enqueue(request);
    }

标签: javaandroid

解决方案


推荐阅读