joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 772 forks source link

Error: There was a problem parsing the package #595

Closed mav-raj closed 4 years ago

mav-raj commented 4 years ago

Version of installed library and RN project. rn-fetch-blob:0.11.2 RN: 0.61.5 android: 10 gradle Target SDK: 29

manifest.xml <manifest ... > <application android:requestLegacyExternalStorage="true" ... >

A sample code snippet const handleUpdate = async () => { const android = RNFetchBlob.android; RNFetchBlob.config({ addAndroidDownloads: { useDownloadManager: true, title: 'awesome.apk', description: 'Latest update of awesome App', mime: 'application/vnd.android.package-archive', mediaScannable: true, notification: true, path: RNFetchBlob.fs.dirs.DownloadDir + '/awesome.apk', }, }) .fetch('GET', 'https://example.com/download/awesome.apk') .progress((recieved, total) => { console.log(Math.round(100 (recieved / total))); // NOT WORKING console.log(recieved / total); // // NOT WORKING setRecieved(Math.round(100 (recieved / total))); }) .then(res => { android.actionViewIntent( res.path(), 'application/vnd.android.package-archive', ); }) .catch(e => { const path = RNFetchBlob.fs.dirs.DownloadDir + '/awesome.apk'; RNFetchBlob.fs.unlink(path); ToastAndroid.show( "Can't update, download link not working, try again later", ToastAndroid.SHORT, ToastAndroid.CENTER, ); }); };

ISSUE In download manager, APK gets downloaded successfully, but opens a Alert dialog with a message: "There was a problem parsing the package" and a OK button. Pressing OK button removes the dialog App not installed But clicking downloaded file on notification, Open a prompts to install the app after asking allowing from "unknown resources" and then it get installed.

I tried with both signed and unsigned apk. Didn't work.

mav-raj commented 4 years ago

Since, I was trying this on my initial screen and I don't have the storage permission initially. What I did is ask for storage permission before downloading the update, and now everything works as expected. Closing.

xyw1229 commented 3 years ago

is this 'PERMISSIONS.WRITE_EXTERNAL_STORAGE'? I set this,but it still can not work! still appear this problem.

davidgarra commented 3 years ago

is this 'PERMISSIONS.WRITE_EXTERNAL_STORAGE'? I set this,but it still can not work! still appear this problem.

Did you find a solution?

mav-raj commented 3 years ago

is this 'PERMISSIONS.WRITE_EXTERNAL_STORAGE'? I set this,but it still can not work! still appear this problem. Hello, I fixed this by asking for storage permission. Have a look here