android - 从firebase下载文件时如何显示进度条?
问题描述
我正在尝试设置一个类似于 WhatsApp 的语音邮件,以便用户点击“播放”按钮;该应用程序首先下载文件,然后才允许它播放。下载有效,但我不知道如何集成进度条。
public void Download(){
int mtn = i++ ;
final StorageReference ref2 = storageReference.child("/Audio/").child("new_audio0.mp3");
ref2.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
DownLoadFile(context,"new_audio",".mp3",DIRECTORY_DOWNLOADS, uri);
Log.i("URL_LINK", uri.toString());
Toast.makeText(context, "En cours de télechargement..", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(context, "Le telechargement a échoué", Toast.LENGTH_SHORT).show();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
}
});
}
public void DownLoadFile(Context context , String fileName , String fileExtension, String DestinationDirectory, Uri uri ){
DownloadManager downloadManager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(context,DestinationDirectory, fileName + fileExtension);
assert downloadManager != null;
downloadManager.enqueue(request);
}
解决方案
推荐阅读
- mysql - 从头开始在 nodejs/react 中实现 ABAC
- cordova - 如何在 cordova-vuejs 混合应用程序中生成动态推送通知?
- ubuntu - 构建生产无法分配内存
- kubernetes - 如何将 GKE 集群节点保持在不同区域?
- c# - 单击具有相同类名的多个按钮之一
- sql - 如何从同一列中以特定顺序选择 2 个元素,将它们与另一个属性进行比较?
- java - 使用ByteBuddy实现OpenTracing时如何避免NoClassDefFoundError
- ios - UITableview 中可扩展和可折叠部分的数据结构
- spring-batch - 将 Spring 批处理作为计划任务运行
- c - 生成和捕获无效指令