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

rn-android-apk-install

v0.0.3

Published

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

Downloads

3

Readme

React Native APK Installer

npm version

Install an Android APK from your react-native project. This project is based react-native-install-apk with enhancements to support current RN versions.

Installing ApkInstaller

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

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

      ...
    
      dependencies {
          ...
          implementation project(':rn-android-apk-install')
      }
  • Add the following to android/app/src/main/java/**/MainApplication.java:

      ...
      import com.wl.apkinstall.ApkInstallerPackage;  // add this for rn-android-apk-install
    
      public class MainApplication extends Application implements ReactApplication {
    
          @Override
          protected List<ReactPackage> getPackages() {
              return Arrays.<ReactPackage>asList(
                  new MainReactPackage(),
                  ...
                  new ApkInstallerPackage()     // add this for rn-android-apk-install
              );
          }
      }
  1. Add the following to your AndroidManifest.xml file. Take note of the value of android:authorities. It will be used in the last step. For example, (APP_BUNDLE_ID).provider.
     <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
  <provider
          android:name="android.support.v4.content.FileProvider"
          android:authorities="${applicationId}.provider"
          android:exported="false"
          android:grantUriPermissions="true"
          tools:replace="android:authorities">
          <!-- you might need the tools:replace thing to workaround rn-fetch-blob or other definitions of provider -->
          <!-- just make sure if you "replace" here that you include all the paths you are replacing *plus* the cache path we use -->
          <meta-data tools:replace="android:resource"
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/filepaths"/>
      </provider>
  1. Create a file named filepaths.xml in the res/xml directory & append it with the following content.
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">


  <!-- Select one of the following based on your apk location -->

  <!-- cache dir is always available and requires no permissions, but space may be limited -->
  <cache-path name="cache" path="/" />
  <root-path name="root" path="." />

  <!-- <files-path name="name" path="/" />  -->

  <!-- External cache dir is maybe user-friendly for downloaded APKs, but you must be careful. -->
  <!-- 1) in API <19 (KitKat) this requires WRITE_EXTERNAL_STORAGE permission. >=19, no permission -->
  <!-- 2) this directory may not be available, check Environment.isExternalStorageEmulated(file) to see -->
  <!-- 3) there may be no beneifit versus cache-path if external storage is emulated. Check Environment.isExternalStorageEmulated(File) to verify -->
  <!-- 4) the path will change for each app 'com.example' must be replaced by your application package -->
  <!-- <external-cache-path name="external-cache" path="/data/user/0/com.example/cache" /> -->

  <!-- Note that these external paths require WRITE_EXTERNAL_STORAGE permission -->
  <!-- <external-path name="some_external_path" path="put-your-specific-external-path-here" />  -->
  <!-- <external-files-path name="external-files" path="/data/user/0/com.example/cache" />  -->
  <!-- <external-media-path name="external-media" path="put-your-path-to-media-here" />  -->
</paths>
  1. Lastly, add import ApkInstaller from 'rn-android-apk-install' to the list of imports. (You might also need to install react-native-fs package). Note: Your file provider ID must be the same as the one you've defined in step 4
  import RNFS from 'react-native-fs';
  import ApkInstaller from 'rn-android-apk-install'

   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, 'com.your.application.provider');
         }
       });
   }
   catch(error) {
       console.warn(error);
   }