Reputation: 740
I have an existing react native app that I added some features and want to update it grammatically. my problem is after installation my app is closed for no reason but app updates seccussfully. how can I prevent this
my build.gradle
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
my react-native download section
downloadClick = async () => {
const { Model } = this.props;
try {
await requestPermission(Permissions.WRITE_EXTERNAL_STORAGE, trans('STORAGE_MESSAGE'));
await requestPermission(Permissions.WRITE_EXTERNAL_STORAGE, trans('REQUEST_INSTALL_PACKAGES'));
this.downloading(true);
const filePath = `${RNFS.DocumentDirectoryPath}/com.rasapayam.apk`;
RNFS.downloadFile({
// fromUrl: Model.ApkLink.value,
fromUrl: "https://srv-file7.gofile.io/download/2Oyk8V/rasa-60.apk",
toFile: filePath,
progress: (res) => {
this.setState({ progress: (res.bytesWritten / res.contentLength) });
},
progressDivider: 1,
}).promise.then((result) => {
this.downloading(false);
if (result.statusCode === 200) {
MimeIntent.openURLWithMime(filePath, 'application/vnd.android.package-archive');
}
}).catch((err) => {
this.downloading(false);
});
} catch (err) {
ToastAndroid.show(trans('VERSION_ERROR'), ToastAndroid.SHORT);
this.setState({ progress: 0 });
}
}
my android native module for installing downloaded apk
@ReactMethod
public void openURLWithMime(String url, String mime, Promise promise) {
if (url == null || url.isEmpty()) {
promise.reject(new JSApplicationIllegalArgumentException("Invalid URL: " + url));
return;
}
if (ContextCompat.checkSelfPermission(_context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
Activity currentActivity = getCurrentActivity();
Uri contentUri = FileProvider.getUriForFile(_context, "com.rasapayam", new File( url));
Intent install = new Intent(Intent.ACTION_VIEW);
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
install.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
install.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
install.setData(contentUri);
if (currentActivity != null) {
currentActivity.startActivity(install);
} else {
getReactApplicationContext().startActivity(install);
}
promise.resolve(true);
}
}
my manifest's provider on the application's tag
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.rasapayam"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
my provider xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="." />
<external-files-path name="external_files" path="." />
<root-path name="root" path="." />
<files-path
name="files"
path="." />
</paths>
Upvotes: 0
Views: 288
Reputation: 1267
That is a normal rule. Remember when you use Android Studio. When you run an app in your phone or emulator then further run it with an update the app interface closes then installs the new apk. that is a default process. When you install an app with same package name it replace the previous version. this need to stop the current process.
Upvotes: 0
Reputation: 51
I am not an expert here, but I am quite confident that it is natural behavior on android, when you install new app it needs to be closed, Google Play does the same the app closes when it updates. What you would most likely want to achieve is some kind of an OTA update. You can achieve that with Code Push AFAIK.
Upvotes: 1