Code example for DownloadManager

Methods: enqueuequery

1
			return; 
		} 
		 
		Request request = new Request(uri);
		request.setDestinationInExternalFilesDir(context, null, path);
		downloadManager.enqueue(request);
		 
		context.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
	} 
 
	public void downloadToExternalPublicFiles(Uri uri, String path) {
		if(isDownloading(uri)) {
			return; 
		} 
		 
		Request request = new Request(uri);
		request.setDestinationInExternalPublicDir(null, path);
		downloadManager.enqueue(request);
		 
		context.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
	} 
 
	public boolean isDownloading(final Uri uri) {
		switch(getDownloadStatus(uri)) {
			case DownloadManager.STATUS_PAUSED:
			case DownloadManager.STATUS_PENDING:
			case DownloadManager.STATUS_RUNNING:
				return true; 
			case DownloadManager.STATUS_FAILED:
			case DownloadManager.STATUS_SUCCESSFUL:
			default: 
				return false; 
		} 
	} 
 
	private int getDownloadStatus(Uri uri) {		
		Cursor c = downloadManager.query(new Query());
		int position = CursorUtils.findPosition(c, c.getColumnIndex(DownloadManager.COLUMN_URI), uri.toString());
		if(position != -1)
		{ 
			c.moveToPosition(position);
			return c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));