我在我的应用程序中使用Android下载管理器。如何访问下载进度(例如通知中的下载百分比),以便在活动内显示该百分比的进度条?
这是我的下载文件方法:
////////////////////////////////////////////////////////////
//================== btn download set on click listner ===========
////////////////////////////////////////////////////////////
holder.btnDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(questionha.get(position).getQuestionDownLink());
if (!Uri.EMPTY.equals(downloadUri)) {
Request request = new Request(downloadUri);
request.setTitle(questionha.get(position).getQuestionTitle());
request.setDescription("Downloading ....");
request.setDestinationInExternalFilesDir(v.getContext(), "downloaded", questionha.get(position).getQuestionDownFileName());
enqueue = dm.enqueue(request);
}else {
Log.i("Download manager","Download manager url is null !");
}
}
});
`registerContentObserver( Uri.parse( "content://downloads/my_downloads" ), true, YOUR_OBSERVER );`
- cwbowron