Android – I can't open a file from an attempt but from the file explorer

Good day,

I am making an app in which I have to load from the database some cardview with data and image or document, when pressing on this element to obtain the option to download the file and when finished downloading it, offer the possibility of opening it from the application. All that works well until the moment of opening the files (Images, word documents, excel, etc.), at this point it does not show me any error either by the android studio console or by the app as such, only when opening the it comes out as corrupt (when it is an image, although if I open it from the file explorer it opens without problems) and when it is a document it opens as if the file was empty or as if it were a new one.

So I am taking the data through the download manager:

private void executeDownload() {
    ProgressDialog progressDialog = new ProgressDialog(AssignedTasksDetailActivity.this);
    progressDialog.setMessage("Descargando Archivo...");
    // registrer receiver in order to verify when download is complete
    registerReceiver(new DonwloadCompleteReceiver(), new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url_app));
    request.setDescription("Descargando Archivo " + filename);
    request.setTitle("Descargado "+ filename);
    // in order for this if to run, you must use the android 3.2 to compile your app
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
    // get download service and enqueue file
    DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);

Then I show an alertdialog when the download is complete to give the option to open the file (this is where I think it fails):

public class DonwloadCompleteReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
            final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(AssignedTasksDetailActivity.this);
            alertDialogBuilder.setMessage("┬┐Desea abrir este archivo?");
            alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {


            alertDialogBuilder.setPositiveButton("Abrir",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Coop app = ((Coop)getApplicationContext());
                    //File file = new File(filename);  // -> filename = maven.pdf
                    File file = new File(Environment.DIRECTORY_DOWNLOADS, filename);
                    Uri path = FileProvider.getUriForFile(AssignedTasksDetailActivity.this, "", file);
                    String type = url_app.substring(url_app.lastIndexOf('.'), url_app.length());
                    Intent intent = new Intent(Intent.ACTION_VIEW);

                    if(type==".jpg" || type==".jpeg" || type==".png"){
                        intent.setDataAndType(path, "image/*");
                            intent.setDataAndType(path, "application/pdf");
                    }catch(ActivityNotFoundException e){
                        Toast.makeText(AssignedTasksDetailActivity.this, "No hay una aplicacion instalada para abrir este tipo de archivos", Toast.LENGTH_SHORT).show();

I attached my fileprovider configuration to see if that has anything to do with it:


And its xml:


Try to see the file path with a toast and this is what throws me: "content: //".

Thanks in advance.