Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Notification doesn't download file #442

Closed
SergioReis97 opened this issue Jul 25, 2017 · 8 comments
Closed

Notification doesn't download file #442

SergioReis97 opened this issue Jul 25, 2017 · 8 comments

Comments

@SergioReis97
Copy link

Tying to use the option addAndroidDownloads and create a notification but the notification never opens the file.
I can use

let sendIntent = RNFetchBlob.android.actionViewIntent;
sendIntent(path, mimeType);

To open the downloaded file for android and it works accordingly, added it to the notification click (implemented by third party) and everything goes smoothly except that even disabling addAndroidDownloads notification it always stays there... and whenever clicked, it says "can't open file" in a toast and nothing happens.

Here's the complete function i'm currently using to download

  _downloadFile(fileName,url) {
    const PictureDir = RNFetchBlob.fs.dirs.PictureDir;
    var tipoFIcheiro = mimetype.lookup(fileName);
    if (!tipoFIcheiro)
      tipoFIcheiro = "image/png"

    RNFetchBlob
    .config({
        fileCache : true,
        addAndroidDownloads : {
          title : fileName,
          mime : tipoFIcheiro,
          useDownloadManager : true,
          description : fileName,
          mediaScannable : false,
          notification : false,
        }
      })  
      .fetch('GET', url, {
        //some headers ..
      })
      .then((res) => {
        // the temp file path
        let base64Str = res.data;
        let imageLocation = PictureDir + '/' + fileName;
        

        //Save image
        
        fs.writeFile(imageLocation, base64Str, 'base64');
        if (Platform.OS === 'ios') {
          notify("Download Completo",fileName)
        } else {
          notifyFicheiro("Download Completo",fileName,tipoFIcheiro,res.path())
        }
      })
    

  }

Thanks in advance

@SergioReis97
Copy link
Author

SInce i can open the notification i create and opened the file i found out that the file is being saved under /data/user/0/com.android.providers.downloads/cache/downloadfile.bin . Is it possible to save it to the RNFetchBlob.dirs.DocumentDir instead and with the correct extension? that way notification can probably open the file

@wkh237
Copy link
Owner

wkh237 commented Jul 26, 2017

@SergioReis97 , you can add path to addAndroidDownloads.

See the wiki

@SergioReis97
Copy link
Author

Using this still gives the same error when trying to open the file

    .config({
        fileCache : true,
        addAndroidDownloads : {
          title : fileName,
          mime: tipoFIcheiro,
          path:dirs.DCIMDir,
          ext:"png",
          useDownloadManager : true,
          description : fileName,
          mediaScannable : true,
          notification : true,
        }
      })  

@wkh237
Copy link
Owner

wkh237 commented Jul 26, 2017

I think you should also give a filename (also extension) to the path, not folder only 👍

@SergioReis97
Copy link
Author

SergioReis97 commented Jul 26, 2017

Same result actually, it does download and goes to download app but always says "Can't open this file". Same when i click in downloadmanager notification and i can still open it using the custom notification even though it points to "/data/user/0/com.android.providers.downloads/cache/downloadfile.bin"

    let dirs = RNFetchBlob.fs.dirs
    RNFetchBlob
    .config({
        fileCache : true,
        // android only options, these options be a no-op on IOS
        addAndroidDownloads : {
          title : "test.png",
          mime: tipoFIcheiro,
          path:dirs.DCIMDir+"/test.png" ,
          ext:"png",
          useDownloadManager : true,
          description : fileName,
          mediaScannable : true,
          notification : true,
        }
      })  

https://gyazo.com/5801c1764f1831f73aca6f56b6c33688

@wkh237
Copy link
Owner

wkh237 commented Jul 26, 2017

It looks similar to #391

@SergioReis97
Copy link
Author

Re-installing into 0.10.6 didn't work but I copied the changes you've did in and it does indeed solve. Thank you for this amazing project/help :)
ed2732a

@wkh237
Copy link
Owner

wkh237 commented Jul 26, 2017

Great 👍 Nice to know you solve the problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants