Here is how I solve it, you need to make a request to the download manager and check if there is already a download with the same name. if there are no matches, I create a file and use the exist function to check if it is in the download directory. if it does not exist, I start the download.
downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
File ExistingFile = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS) + "/" + Archivos.get(position).getNombre());
Cursor cursor = downloadManager.query( new Query() );
boolean IsInDownloadManager;
IsInDownloadManager = false;
for (int i = 0; i < cursor.getCount() ; i++)
{
cursor.moveToPosition(i);
Log.i("Click Grid", "Objetos en download manager [" + String.valueOf(i) + "] " + cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TITLE)));
if (Archivos.get(position).getNombre().equals(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TITLE)))){
IsInDownloadManager = true;
Log.i("Click Grid", "Objeto está en download Manager " + Archivos.get(position).getNombre());
break;
}
}
if (IsInDownloadManager){
int Status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
Log.i("Click Grid", cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)));
if (Status == DownloadManager.STATUS_SUCCESSFUL){
Toast.makeText(getActivity() ,"Abriendo " + Archivos.get(position).getNombre(), Toast.LENGTH_SHORT).show();
try { openFile(getActivity(),ExistingFile ); } catch (IOException e) {e.printStackTrace();}
}else{
Toast.makeText(getActivity() ,Archivos.get(position).getNombre() + " ya se está descargando", Toast.LENGTH_SHORT).show();
}
}else{
if( ExistingFile.exists() ){
Toast.makeText(getActivity() ,"Abriendo " + Archivos.get(position).getNombre(), Toast.LENGTH_SHORT).show();
try { openFile(getActivity(),ExistingFile ); } catch (IOException e) {e.printStackTrace();}
}else{
DescargarArchivo( Archivos.get(position) );
}
}
}});