react-native-apk-install

A react-native apk installer for Android. This project is based on `react-native-apk-installer`


Keywords
react-native, android, library, apk, installer, react-native-apk-installer
License
MIT
Install
npm install react-native-apk-install@1.0.2

Documentation

react-native-apk-install

A react-native apk installer for Android. This project is based on react-native-apk-installer

Getting started

$ npm install react-native-apk-install --save

Mostly automatic installation

$ react-native link react-native-apk-install

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.wayne.apkinstaller.RNApkInstallPackage; to the imports at the top of the file
  • Add new RNCardviewPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-apk-install'
    project(':react-native-apk-install').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-apk-install/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-apk-install')
    

Usage

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);
     }