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
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" />