When I downloaded apk by download manager, the error occurred.
My code:
const android = RNFetchBlob.android;
RNFetchBlob.config({
addAndroidDownloads: {
useDownloadManager: true,
title: "xxx.apk",
description: "downloading",
mime: "application/vnd.android.package-archive",
mediaScannable: true,
notification: true
}
})
.fetch("GET", appUrl)
.then(res => {
android.actionViewIntent(
res.path(),
"application/vnd.android.package-archive"
);
});
Environment:
OS: Windows 7
Node: 8.12.0
Yarn: 1.9.4
npm: 6.4.1
Watchman: Not Found
Xcode: N/A
Android Studio: Not Found
"rn-fetch-blob": "^0.10.12"
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: ^0.55.4 => 0.55.4
after update code ,an error occurred.
Possible Unhandled Promise Rejection(id:0):
Error:Attempt to invoke virtual method 'android.content.res.XmlResourceParser......
const android = RNFetchBlob.android;
RNFetchBlob.config({
addAndroidDownloads: {
useDownloadManager: true,
title: "xxx.apk",
description: "downloading...",
mime: "application/vnd.android.package-archive",
mediaScannable: true,
path: RNFetchBlob.fs.dirs.DownloadDir + "/" + xxx.apk',
notification: true
}
})
.fetch("GET", appUrl)
.then(res => {
console.warn('res...',res);
android.actionViewIntent(
res.path(),
"application/vnd.android.package-archive"
);
});
same issue
same here
The same issue =(
I use both of RNFS and RNFetchBlob.
I solved this problem with this solution
`
var RNFS = require('react-native-fs');
import RNFetchBlob from 'rn-fetch-blob';
let downloadDest = ${RNFS.ExternalStorageDirectoryPath}/Download/123.jpg;
RNFetchBlob.config({
addAndroidDownloads: {
useDownloadManager: true,
path: downloadDest,
notification: true,
mime: '/'
}).then((res) => {
RNFetchBlob.android.actionViewIntent(res.path(), '/')
})
`
It works to me. good luck.
I use both of RNFS and RNFetchBlob.
I solved this problem with this solution
`
var RNFS = require('react-native-fs');
import RNFetchBlob from 'rn-fetch-blob';let downloadDest =
${RNFS.ExternalStorageDirectoryPath}/Download/123.jpg;RNFetchBlob.config({
addAndroidDownloads: {
useDownloadManager: true,
path: downloadDest,
notification: true,
mime: '_/_'
}).then((res) => {
RNFetchBlob.android.actionViewIntent(res.path(), '_/_')
})
`It works to me. good luck.
Worked for me! Thanks
This is due to a bug in RNFetchBlobReq.java's onReceive.
It throws this error if path was not provided and it has not retrieved a filePath from the DownloadManager result:
if (options.addAndroidDownloads.hasKey("path")) {
...
}
else {
if(filePath == null)
this.callback.invoke("Download manager could not resolve downloaded file path.", RNFetchBlobConst.RNFB_RESPONSE_PATH, null);
else
...
}
_However_, it does not bother trying to retrieve filePath (even though it _is_ available) unless mime was set _and_ it was set to image:
if ( contentUri != null &&
options.addAndroidDownloads.hasKey("mime") &&
options.addAndroidDownloads.getString("mime").contains("image")) {
Uri uri = Uri.parse(contentUri);
Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
// use default destination of DownloadManager
if (cursor != null) {
cursor.moveToFirst();
filePath = cursor.getString(0);
cursor.close();
}
}
I don't have time to submit a PR right now, but I believe this would be trivial to fix by changing the logic to:
if ( contentUri != null ) {
Uri uri = Uri.parse(contentUri);
Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Files.FileColumns.DATA}, null, null, null);
The path check in that first code snippet is why adding that property to your config can work around the issue.
(also this was previously reported in the original project: https://github.com/wkh237/react-native-fetch-blob/issues/606)
I fixed this issue by including the path inside the addAndroidDownloads object.
RNFetchBlob.config({
fileCache : true,
path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf',
addAndroidDownloads : {
notification : true,
useDownloadManager: true,
title : 'test-report-'+data.id+'.pdf',
mime : 'application/pdf',
description : 'Your test reports.',
path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', <--- Right here
}
})
After that the res.path() returns the right location and I can open the pdf file which I have downloaded.
I fixed this issue by including the path inside the addAndroidDownloads object.
RNFetchBlob.config({
fileCache : true,
path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf',
addAndroidDownloads : {
notification : true,
useDownloadManager: true,
title : 'test-report-'+data.id+'.pdf',
mime : 'application/pdf',
description : 'Your test reports.',
path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', <--- Right here
}
})After that the res.path() returns the right location and I can open the pdf file which I have downloaded.
There is no need to add path and file cache in config field, Download manager ignore both the fields. Having path defined in addAndroidDownloads is enough to work.
I fixed this issue by including the path inside the addAndroidDownloads object.
RNFetchBlob.config({
fileCache : true,
path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf',
addAndroidDownloads : {
notification : true,
useDownloadManager: true,
title : 'test-report-'+data.id+'.pdf',
mime : 'application/pdf',
description : 'Your test reports.',
path : dirs.DownloadDir + '/test-report-'+data.id+'.pdf', <--- Right here
}
})After that the res.path() returns the right location and I can open the pdf file which I have downloaded.
this one worked for me. Thank you very much
Most helpful comment
I use both of RNFS and RNFetchBlob.
I solved this problem with this solution
`
var RNFS = require('react-native-fs');
import RNFetchBlob from 'rn-fetch-blob';
let downloadDest =
${RNFS.ExternalStorageDirectoryPath}/Download/123.jpg;RNFetchBlob.config({
addAndroidDownloads: {
useDownloadManager: true,
path: downloadDest,
notification: true,
mime: '/'
}).then((res) => {
RNFetchBlob.android.actionViewIntent(res.path(), '/')
})
`
It works to me. good luck.