如何在progess中显示'下载'当我从另一个活动返回时,在RecyclerView中的多个视频的进度条?

时间:2018-06-02 17:48:58

标签: android android-progressbar

我有一个ListView,其中包含一个视频列表和点击下载视频按钮,它在循环进度条中显示下载进度。如果我点击一个数字视频进行下载,那么它将开始显示进度。但是当我点击另一个活动并返回相同的活动时,剩余的进度不会显示在进度条中,也不会显示。

我应该怎样做才能看到之前点击的ListView中的剩余视频进度?我使用下载管理器下载视频并在进度条中显示进度。

我想要与WhatsApp中使用的功能相同;如果您点击某个视频,它会显示下载进度,也会在您重新访问该页面后显示。

1 个答案:

答案 0 :(得分:0)

我们必须在本地数据库中保存downloadId。 `DownloadManager manager =(DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);                                     DownloadManager.Request request = new DownloadManager.Request(Uri.parse(strUrl));                                     request.allowScanningByMediaScanner();                                     request.setTitle(strDownloadFileName);                                     request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,strDownloadFileName);                                     request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);                                     long downloadId = manager.enqueue(request);

                                databaseHelper.insertProgress(positionItem,downloadId);'

创建针对downloadId获取进度的函数 `private int getProgressFromDownloadID(long donloadId){

    DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Query q = new DownloadManager.Query();
    q.setFilterById(donloadId);

    Cursor  cursor = manager.query(q);
    cursor.moveToFirst();
    int bytes_downloaded = cursor.getInt(cursor
            .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
    int bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));

    if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL) {

    }

    int dl_progress = (int) ((double)bytes_downloaded / (double)bytes_total * 100f);

    return dl_progress;
}`