应用升级

12147

安卓应用升级

  1. web端读取_constant表中version的信息
  1. // web端读取_constant表中version的信息
  2. async versionCheck() {
  3. setTimeout(async () => {
  4. await this.versionCheck();
  5. }, 10000);
  6. const versionConstantKey = 'version';
  7. let data;
  8. data = (
  9. await window.jianghuAxios({
  10. data: {
  11. appData: {
  12. pageId: 'allPage',
  13. actionId: 'getConstantList'
  14. }
  15. }
  16. })
  17. ).data.appData.resultData;
  18. const {rows: constantList} = data;
  19. localStorage.setItem('constantsArray', JSON.stringify(constantList));
  20. const serverVersionMap = constantList.find(item => item.constantKey === versionConstantKey);
  21. const serverVersion = JSON.parse(serverVersionMap.constantValue);
  22. window.serverVersion = serverVersion;
  23. },
  24. // 获取版本号
  25. function getServerVersion() {
  26. if (window.serverVersion) {
  27. return JSON.stringify(window.serverVersion);
  28. }
  29. }
  1. APP端,每15秒读取version信息
  1. //代码来源:/jianghuAppBrowser/jianghuBrowser/lib/Utils/LocalStorageUtil.dart
  2. static Future<void> looperGetServerVersion(BuildContext context, String _runningPage) async {
  3. if(Constants.appId.value == 'browser' && Constants.isLoginPage) {
  4. return;
  5. }
  6. if(RenderKey.controller.value == null) {
  7. return;
  8. }
  9. if (WebViewHandler().complete) {
  10. String serverVersion = await RenderKey.controller.value!.runJavascriptReturningResult("getServerVersion()");
  11. if (serverVersion != "null" && serverVersion != "(null)") {
  12. try {
  13. Map<String, dynamic> versionMap = Utils.replaceAllJsonString(serverVersion);
  14. Constants.serverVersion = ServerVersionEntity.fromJson(versionMap);
  15. Constants.webVersion = Constants.serverVersion.version;
  16. if (Platform.isAndroid) {
  17. VersionUtil.updateApp(context);
  18. }
  19. } catch (error) {
  20. print("localStorage serverVersion error: $error");
  21. }
  22. }
  23. }
  24. if(_runningPage == runningPage) {
  25. Future.delayed(const Duration(seconds: 15), () async {
  26. looperGetServerVersion(context, _runningPage);
  27. });
  28. }
  29. }
  1. 下载并安装app
  • 参考:/jianghuAppBrowser/jianghuBrowser/lib/Utils/VersionUtil.dart

  • 流程:updateApp -> checkNeedUpdate -> downloadApk -> updateDialogRunUpdateBtn -> downloadImpl -> downloadFile -> installApk