1

I want to update my existing app using rn-fetch-blob. I have already installed my apk in my mobile having

  versionCode 1
  versionName "0.4.5"

Now I am downloading a new apk file from s3 bucket having

  versionCode 1
  versionName "0.4.6"

using rn-fetch-blob as mentioned in this thread with the following code

const RNFetchBlob = require('rn-fetch-blob').default
const updateApp = () => {
    console.log("App Update")
    const android = RNFetchBlob.android;
    let dirs = RNFetchBlob.fs.dirs;
    RNFetchBlob.config({
      addAndroidDownloads: {
        useDownloadManager: true,
        title: 'App-Testing',
        description: 'An APK that will be installed',
        mime: 'application/vnd.android.package-archive',
        mediaScannable: true,
        notification: true,
        path: RNFetchBlob.fs.dirs.DownloadDir + '/app-release.apk',
      },
    })
      .fetch(
        'GET',
        'https://testing-avinash-v1.s3.eu-north-1.amazonaws.com/app-release.apk',
      )
      .then(res => {
        android.actionViewIntent(
          res.path(),
          'application/vnd.android.package-archive',
        );
      });

I am able to download the apk file but it is not updating the existing apk automatically. Is there any way I can achieve the expected result

Avinash A
  • 665
  • 1
  • 7
  • 22
  • It won't install it automatically, you have to tell it to install the file. There are some ideas here: https://stackoverflow.com/questions/4604239/install-application-programmatically-on-android – Abe Mar 11 '23 at 02:22

1 Answers1

1

I am able to resolve this issue by modifying my code to update the apk with the following code

const updateApp = async () => {
  const RNFetchBlob = require("rn-fetch-blob").default;
  RNFetchBlob.config({
    addAndroidDownloads: {
      useDownloadManager: true,
      title: "App-Testing",
      description: "An APK that will be installed",
      mime: "application/vnd.android.package-archive",
      mediaScannable: true,
      notification: true,
      path: RNFetchBlob.fs.dirs.DownloadDir + "/app-release.apk",
    },
  })
    .fetch(
      "GET",
      "https://testing-avinash-v1.s3.eu-north-1.amazonaws.com/app-release.apk"
    )
    .then(async (res) => {
      RNFetchBlob.android
        .actionViewIntent(
          RNFetchBlob.fs.dirs.DownloadDir + "/app-release.apk",
          "application/vnd.android.package-archive"
        )
        .then(() => {
          console.log("success");
        })
        .catch((err) => {
          console.log("error", err);
        });
    });
};

And Modifying Androidmanifest.xml file with the following permission

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
Avinash A
  • 665
  • 1
  • 7
  • 22