如何查询系统DownloadProvider中的所有下载项?

时间:2016-04-22 03:57:03

标签: android android-download-manager

是否有任何方法可以从系统下载提供者查询所有下载项目,我这样做,但它需要权限:android.permission.ACCESS_ALL_DOWNLOADS,最糟糕的是,此权限是签名级别,我可以&#39获得此权限,是否有其他解决方案可以执行此操作。我只是想开发一个应用程序来管理系统的下载。非常感谢!

int columnId = c.getColumnIndex(DownloadManager.COLUMN_ID);
            int columnTitle = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
            Log.d(TAG, "query complete!-->" + c.getCount());
            for (int i = 0; c.getColumnName(i) != null; i++)
                Log.d(TAG, c.getColumnName(i));
            while (c.moveToNext()) {
                int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
                long id = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID));
                String title = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
                switch (status) {
                case DownloadManager.STATUS_PAUSED:
                    Log.d(TAG, "query one  paused task:" + status + "-" + title + "-" + id);
                    break;
                case DownloadManager.STATUS_PENDING:
                    Log.d(TAG, "query one  pending task:" + status + "-" + title + "-" + id);
                    break;
                case DownloadManager.STATUS_RUNNING:
                    Log.d(TAG, "query one  running task:" + status + "-" + title + "-" + id);
                    break;
                case DownloadManager.STATUS_SUCCESSFUL:
                    Log.d(TAG, "query one  success task:" + status + "-" + title + "-" + id);
                    break;
                case DownloadManager.STATUS_FAILED:
                    Log.d(TAG, "query one failed task:" + status + "-" + title + "-" + id);
                    // downloadManager.remove(id);
                    break;
                }
            }

1 个答案:

答案 0 :(得分:0)

正如您所发现的,查询content://downloads/all_downloads Uri的唯一方法是使用android.permission.ACCESS_ALL_DOWNLOADS,这是一个签名级别权​​限。这是故意的,意味着无法从未使用系统签名签名的第三方应用程序读取所有下载。