react-native-android-update-matt
v1.0.11
Published
A ReactNative Update Component for android
Downloads
4
Maintainers
Readme
react-native-android-update-matt
Getting started
$ npm install react-native-android-update-matt --save
Mostly automatic installation
$ react-native link react-native-android-update-matt
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.matt.rn.android.update.RNAndroidUpdateMattPackage;
to the imports at the top of the file - Add
new RNAndroidUpdateMattPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-android-update-matt' project(':react-native-android-update-matt').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-update-matt/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-android-update-matt')
Usage
import AndroidUpdate from 'react-native-android-update-matt';
componentDidMount() {
this.upgradeTimer = setTimeout(() => {
let url = x;
let version = y;
let options = {token:xxx, dlUrlPrefix:xxx};
AndroidUpdate.update(url, version, options);
}, 500);
}
componentWillUnmount() {
this.upgradeTimer && clearTimeout(this.upgradeTimer);
}
@RequestMapping("/appUpdate")
public Response appUpdate() {
Map map = new HashMap();
map.put("version", "x.x.x");
map.put("description", new String[] {"xxx","xxx");
map.put("url", "http://xxx.xxx.xxx.xxx/xx.apk");
return new Response().success(map);
}
Response from server:
-----
{
success: true,
result {
version: 'x.x.x',
description: ["xxx","xxx"],
url: 'http://xxx.xxx.xxx.xxx/xx.apk'
}
}