npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-android-background-files-upload

v1.0.0

Published

## Android Files Upload with Notification Progress Bar in Background

Downloads

5

Readme

react-native-notification-background-files-upload

Getting started

$ npm install react-native-notification-background-files-upload --save

Mostly automatic installation

$ react-native link react-native-notification-background-files-upload

Manual installation

This library currently only working in Android.

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-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 PhasesLink 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
  1. 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')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:

      compile project(':react-native-notification-background-files-upload')
  3. we are using okhttp to upload files so please add these dependency to your android/app/build.gradle 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'
  4. put service and receiver tag in android/app/src/main/AndroidManifest.xml:

    1. add these permission inside the menifest tag:
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <!-- FOREGROUND_SERVICE Required If you want to perform Background Operation in Android Pie or Higher.
         If you not give this permission in manifest it will lead to Runtime Crash.-->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    1. Add thes inside the application tag
     <!--This Receiver Action CONNECTIVITY_CHANGE Work in API Level 24or Lower-->
        <receiver android:name="com.nbfu.backgroundFilesUpload.broadcast.UploadBroadCast">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
            </intent-filter>
        </receiver>
    
        <!--This Service Work in API Level 20 or Lower-->
        <service android:name="com.nbfu.backgroundFilesUpload.services.UploadService"
            android:process=":UploadService"
            android:enabled="true"/>
    
        <!--This Service Work in API Level 21 or Higher-->
        <service android:name="com.nbfu.backgroundFilesUpload.services.UploadJobService"
            android:permission="android.permission.BIND_JOB_SERVICE"
            android:enabled="true"/>
    
    			<activity
            android:name="com.nbfu.backgroundFilesUpload.NotificationActivity"
            android:taskAffinity=""
            android:excludeFromRecents="true">
        </activity>
    
        <activity android:name="com.nbfu.backgroundFilesUpload.RestartJobActivity"
            android:taskAffinity=""
            android:excludeFromRecents="true"/>

Usage

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");
          }
        }
      );
  1. resume upload process which is finshed by System :-
    //resumeService()
    RNNotificationBackgroundFilesUpload.resumeService()
5) stop process if not needed.
    //stopService()
     RNNotificationBackgroundFilesUpload.stopService();