Search code examples
androidandroid-download-manager

How to query all the download item from the system DownloadProvider?


is there any method to query all the download item from the system downloadprovider,i do this like that,but it need the permission:android.permission.ACCESS_ALL_DOWNLOADS,and worstly,this permission is in signature level,i can't get this permission,is there other solution to do this.And i just want to develop an app to manager the downloads of the system.thanks a lot!

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;
                }
            }

Solution

  • As you discovered, the only way to query the content://downloads/all_downloads Uri is with the android.permission.ACCESS_ALL_DOWNLOADS, which is a signature level permission. This is intentional and means that it is not possible to read all downloads from a third party app not signed with the system signature.