Android Downloads Suddenly Crashes App After Working Fine
See original GitHub issueok so my app was working perfect downloading with no issues at all i tried it on a firestick / nvidia shield and android TV emulator and it was working perfect one day but the next day when i opened the app to try it again the app crashes every time a download starts.
this is the version of react-native i am using and the version of rn-fetch-blob
“react-native”: “0.57.8”, “rn-fetch-blob”: “^0.10.15”
i have tried creating a new project and adding in just the modules needed for the downloads and used a static link to an apk file i know works perfectly fine and it does work perfect for a few tries but again when the app is closed and reopened sometime later it crashes again after a download starts.
this is the code for my downloads
console.log("Download Starting");
const android = RNFetchBlob.android;
const filename = APK_TITLE + ((Math.random() * 1000) | 0) + '.apk';
const filePath = RNFetchBlob.fs.dirs.DownloadDir + '/' + filename ;
console.log('Saving File To : ' + filePath);
this.setState({AppName: APK_TITLE});
this.setState({ Mode: 'download' });
let APKDownload = RNFetchBlob.config({
addAndroidDownloads : {
useDownloadManager : false,
mediaScannable : true,
notification : true,
mime : 'application/vnd.android.package-archive',
title : filename,
description : APK_DESC,
path: filePath
}
})
.fetch('GET', APK_URL);
jobId = APKDownload.taskId;
console.log(jobId);
setTimeout(()=>{
APKDownload.progress({ count : 1 },(received,total)=>{
const percentage = (received / total).toFixed(2);
const text = percentage;
console.log('Download Progress : ' + text);
this.setState({progress: text});
})
}, 0)
APKDownload.then(async (res)=>{
this.setState({Mode: 'apks'});
this.setState({AppName: ''});
this.setState({progress: 0.00});
console.log('Installing APK');
android.actionViewIntent(res.path(), 'application/vnd.android.package-archive');
}).catch((err)=>{
//you must add this line. If you don't add, your app users waste they're storage
//RNFetchBlob.fs.unlink(filePath);
console.log(err)
})
}
after attaching a debugger in android studio i have found this
I/ReactNativeJS: Download Process Starting
APK Saving To : /storage/emulated/0/Download/Cyberflixx150.apk
I/ReactNativeJS: Download ID Assigned : wz3qit80wzj2h01bn6n5
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.update, PID: 14132
java.lang.IllegalArgumentException: path can't be null
at android.app.DownloadManager.validateArgumentIsNonEmpty(DownloadManager.java:1418)
at android.app.DownloadManager.addCompletedDownload(DownloadManager.java:1375)
at android.app.DownloadManager.addCompletedDownload(DownloadManager.java:1325)
at com.RNFetchBlob.RNFetchBlobReq$3.onResponse(RNFetchBlobReq.java:443)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
the path is clearly set and even if i remove the let apk path veriable and set the path in path: still the same error 😕
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top GitHub Comments
I have solved this problem,but i used the downloadManager.Following is the code:
The difference with the official document is that i added the path optional field in the addAndroidDownloads object.When i delete the path field,the it will come into the catch code,then download the app will be wrongly.
the version of react-native i am using and the version of rn-fetch-blob are “react-native”: “0.57.3”, “rn-fetch-blob”: “^0.10.15”, and the os is macOS 10.13.6
@Rob2k9 Could you share your code that resolve this problem ? I need a progress in my app to show user.