## Android Files Upload with Notification Progress Bar in Background
npm install react-native-android-background-files-upload$ npm install react-native-notification-background-files-upload --save
$ react-native link react-native-notification-background-files-upload
#### iOS
1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]
2. Go to node_modules ➜ react-native-notification-background-files-upload and add RNNotificationBackgroundFilesUpload.xcodeproj
3. In XCode, in the project navigator, select your project. Add libRNNotificationBackgroundFilesUpload.a to your project's Build Phases ➜ Link Binary With Libraries
4. Run your project (Cmd+R)<
#### Android
1. Open up android/app/src/main/java/[...]/MainActivity.java
- Add import com.nbfu.backgroundFilesUpload.RNNotificationBackgroundFilesUploadPackage; to the imports at the top of the file
- Add new RNNotificationBackgroundFilesUploadPackage() to the list returned by the getPackages() method
2. Append the following lines to android/settings.gradle:
```
include ':react-native-notification-background-files-upload'
project(':react-native-notification-background-files-upload').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notification-background-files-upload/android')
android/app/build.gradle
3. Insert the following lines inside the dependencies block in :`
`
compile project(':react-native-notification-background-files-upload')
android/app/build.gradle
4. we are using okhttp to upload files so please add these dependency to your react native project:`
`
implementation "com.squareup.okhttp3:okhttp:3.0.1"
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.0.1"
implementation 'com.google.code.gson:gson:2.8.5'
android/app/src/main/AndroidManifest.xml
5. put service and receiver tag in :`
1) add these permission inside the menifest tag:
`
`
2) Add thes inside the application tag
android:enabled="true"/>
android:enabled="true"/>
android:taskAffinity=""
android:excludeFromRecents="true">
android:excludeFromRecents="true"/>
`
javascript
import RNNotificationBackgroundFilesUpload from 'react-native-notification-background-files-upload';
// TODO: What to do with the module?
` 1) start upload Service :-
`
//NOTE:- bcoz you are accessing media files path from Gallery so you //need to ask for run time Permission throught React Native code.
const headers = new Array();
const datas = new Array();
for(let i=0; i < this.state.filePathArray.length; i++){
let head = {'key' : 'test1234',
'orderid' : '1234567',
'filename' : this.state.fileNameArray[i] };
headers[i] = head;
datas[i] = {
'image': this.state.filePathArray[i],// make sure key always be 'image'
'type' : 'image/jpeg' //Make sure key always be 'type',
'delete': true // if you want to delete cache file by default value is false };
}
const filesData = {
'url': 'http://www.example.com/api',
'network_type': 2,
// 2 for Wifi, 1 for Any, 0 for None, 3 for Not Roaming, 4 for Cellular data
'headers': headers,
'datas': datas,
};
// 1 is order_id must be send
RNNotificationBackgroundFilesUpload.startService('upload_notification',filesData, 1,
(status, message) => {
if(status){
alert(message)
}else {
alert(message)
}
});
` 2) check connectivity Status of device :-
`
//isConnected()
RNNotificationBackgroundFilesUpload.isConnected(
(status, message, type) => {
if(status){
if(type == "TYPE_WIFI"){
alert(message);
}else if(type == "TYPE_MOBILE"){
alert(message);
}else if(type == "TYPE_NONE"){
alert(message);
}else {
alert("Something Went Wrong");
}
}else {
alert(message);
}
}
);
` 3) check process is remain or not and if remain then resume process :-
`
//isUploadRemaining()
RNNotificationBackgroundFilesUpload.isUploadRemaining(
(isRemain) => {
if(isRemain) {
alert("Uploading is Remain Do you want to Upload file Again");
RNNotificationBackgroundFilesUpload.resumeService()
} else {
alert("No Upload Remain");
}
}
);
`
4) resume upload process which is finshed by System :-
`
//resumeService()
RNNotificationBackgroundFilesUpload.resumeService()
`
5) stop process if not needed.
`
//stopService()
RNNotificationBackgroundFilesUpload.stopService();
``