Git Product home page Git Product logo

react-native-apk-installer's Introduction

React Native APK Installer

Install an android APK from your react-native project. This project is based on react-native-android-library-boilerplate and react-native-install-apk

Installing ApkInstaller

  1. Add react-native-apk-installer to your project
  • Install directly from npm: npm install --save react-native-apk-installer.
  • Or do npm install --save git+https://github.com/null--/react-native-apk-installer.git in your main project.
  1. Link the library:
  • Add the following to android/settings.gradle:

      include ':react-native-apk-installer'
      project(':react-native-apk-installer').projectDir = new File(settingsDir, '../node_modules/react-native-apk-installer/android')
    
  • Add the following to android/app/build.gradle:

      ...
    
      dependencies {
          ...
          compile project(':react-native-apk-installer')
      }
  • Add the following to android/app/src/main/java/**/MainApplication.java:

      ...
      import com.cnull.apkinstaller.ApkInstallerPackage;  // add this for react-native-apk-installer
    
      public class MainApplication extends Application implements ReactApplication {
    
          @Override
          protected List<ReactPackage> getPackages() {
              return Arrays.<ReactPackage>asList(
                  new MainReactPackage(),
                  ...
                  new ApkInstallerPackage()     // add this for react-native-apk-installer
              );
          }
      }
  1. Simply import ApkInstaller from 'react-native-apk-installer' (You might also need to install react-native-fs package).
  import RNFS from 'react-native-fs';
  import ApkInstaller from 'react-native-apk-installer'

   try {
       var filePath = RNFS.CachesDirectoryPath + '/com.example.app.apk';
       var download = RNFS.downloadFile({
         fromUrl: 'http://example.com/com.example.app.apk',
         toFile: filePath,
         progress: res => {
             console.log((res.bytesWritten / res.contentLength).toFixed(2));
         },
         progressDivider: 1
       });

       download.promise.then(result => {
         if(result.statusCode == 200) {
           console.log(filePath);
           ApkInstaller.install(filePath);
         }
       });
   }
   catch(error) {
       console.warn(error);
   }

react-native-apk-installer's People

Contributors

null-- avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

react-native-apk-installer's Issues

Error: exposed beyond app through Intent.getData()

Getting the following error trying to install an apk:

file:///data/user/0/com.example.app/cache/newApk.apk exposed beyond app through Intent.getData()

React Native Version: 0.55.4
Testing on a real device with Android version 7.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.