react-native-background-upload: Events are not fired on Android
Hi, I need to upload files to Amazon S3 in my app. Everything works fine on the iOS, but I have some troubles with Android.
Here is the example
Upload.startUpload({
url: upload_url,
method: 'PUT',
path: Platform.OS === 'ios' ? path : path.replace('file://', ''),
headers: {
'Content-Type': mimeType,
'Content-Length': size + '',
},
}).then(uploadId => {
Upload.addListener('progress', uploadId, console.log);
Upload.addListener('error', uploadId, console.log);
Upload.addListener('cancelled', uploadId, console.log);
Upload.addListener('completed', uploadId, console.log);
}).catch(err => {
console.log('Upload error!', err);
});
For some reason, none of the progress, error, canceled and completed events are not fired after the upload starts. I get an uploadId and nothing happens after that.
I’ve tried manipulating the SDKs versions (from this issue as well), upgrading React Native to the latest release, scanning the adb logcat. I’ve even put logs in the library’s Java startUpload method, but everything seems to be fine. Do you have any idea what could go wrong? Perhaps your library has conflicts with another lib?
React Native version: 0.52.0 react-native-background-upload version: 4.4.0 Devices: OnePlus 5 with Android 8 and 8.1, Google Pixel 2XL emulator with Android 7.x
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 31 (6 by maintainers)
Hoping that a new comment will raise this issue up: I have the same problem, and manifest update didn’t help
Woohoo, finally found the problem! 🎉
I needed to add the following to my apps AndroidManifest.xml
The intent filter is not really super-necessary, but you might get warnings while building. This is to prevent other apps of starting this service, I guess…
@gotev It looks like the RN build process was not merging in the AndroidManifest.xml from your package! 😮
I’m experiencing the same issue on 5.0, react-native 0.56 I’ve tried the AndroidManifest.xml addition mentioned above, but it didn’t seem to do anything. However, I’m not sure if I’m putting it in the right part of the file. Where exactly in the file should it go? Directly inside the ‘manifest’ tags, ‘application’, or elsewhere? Thanks for any help
@sraka1 I think the problem has to be inspected at RN bridge level, because the service works successfully in production on all Androids and no errors like this ever happened. I encourage you to try the upload service demo app in the same environment in which you start your RN app and it should work. Adjust it with your custom parameters so it can make the same request to your backend.
The
startUploadmethod simply fires an intent, and all the other stuff which triggers the service is pure native Android SDK. If the service does not get triggered at all, maybe there’s something in the RN context which gets passed down the line. Check if it’s the current activity context or the application context to start with. Then, once you make the demo app work, inspect it with Android Studio step by step. Then do the same with the RN app and I’m sure you will get some insights. If it’s an RN bug, with this kind of analysis you can ask for help by RN devs, which could replicate the issue you are facing and help you better than me.Be sure to enable library debug log in all your tests, so you will get very verbose and detailed step by step logs which can help you debug.