Code example for DownloadManager

Methods: getUriForDownloadedFilequery

0
                                     id, getDownloadFailureReason(id)));
            callback.onError();
            return; 
        } 
 
        Uri uri = downloadManager.getUriForDownloadedFile(id);
        Log.v(TAG, String.format("File %s downloaded successfully", uri.getPath()));
 
        callback.onFinish(uri);
    } 
 
    private boolean isDownloadSuccessful(long id) {
        int status = getDownloadQueryAsInt(id, DownloadManager.COLUMN_STATUS);
        return (DownloadManager.STATUS_SUCCESSFUL == status);
    } 
 
    private int getDownloadFailureReason(long id) {
        return getDownloadQueryAsInt(id, DownloadManager.COLUMN_REASON);
    } 
 
    private int getDownloadQueryAsInt(long id, String column) {
        Query query = new Query();
        query.setFilterById(id);
 
        Cursor c = downloadManager.query(query);
        if (!c.moveToFirst()) {
            return -1; 
        } 
 
        int columnIndex = c.getColumnIndex(column);