Flutter updates the installation package in the App and tears the interviewer by hand



3.  With local version For information comparison, select whether to display the update pop-up window. We use event\_bus trigger



if (localVersion == remoteVersion) return;eventManager.eventBus.fire(new UpdateAppEvent(versionInfo));



4.  When upgrading the version, pay attention to the difference Android And IOS (1) IOS to update app package



IOS The processing method of is relatively simple. Jump directly to appStore Yes, I use it here urlLauncher Direct jump



urlLauncher.launch(_link);



(2) Android to update app package



You need to open the storage permission. If you don't have permission, you can apply



import 'package:permission_handler/permission_handler.dart';

///Check if you have permission for Android

Future checkPermission() async {

if (_flatform == 'android') {

  PermissionStatus permission = await PermissionHandler()

      .checkPermissionStatus(PermissionGroup.storage);

  if (permission != PermissionStatus.granted) {

    Map<PermissionGroup, PermissionStatus> permissions =

        await PermissionHandler()

            .requestPermissions([PermissionGroup.storage]);

    if (permissions[PermissionGroup.storage] == PermissionStatus.granted) {

      return true;

    }

  } else {

    return true;

  }

} else {

  return true;

}

return false;

}



Need in Android of AndroidManifest.xml File add permission configuration





**download apk**According to the returned download link, you need to Android The package file is downloaded locally. The file stream needs to be operated here. I use the download tool HTTP Request tool library dio,Professional download plug-ins can also be used here flutter\_downloader,This plug-in supports Android,IOS Download, but the configuration is complicated. I tossed about for a long time and failed to configure it successfully. Anyone who plays with this plug-in can recommend some articles to me.



import 'package:dio/dio.dart';

import 'package:path_provider/path_provider.dart';

///Download Android update package

Future downloadAndroid(String url) async {

///Create storage file

Directory storageDir = await getExternalStorageDirectory();

String storagePath = storageDir.path;

File file = new File(' s t o r a g e P a t h / storagePath/ storagePath/{Config.APP_NAME}v${_version}.apk');

if (!file.existsSync()) {

file.createSync();

}

try {

///Initiate download request

Response response = await Dio().get(url,

    onReceiveProgress: showDownloadProgress,

    options: Options(

      responseType: ResponseType.bytes,

      followRedirects: false,

    ));

file.writeAsBytesSync(response.data);

return file;

} catch (e) {

print(e);

}

}



**install apk**



import 'package:install_plugin/install_plugin.dart';

///Install apk

Future installApk(String url) async {

File _apkFile = await downloadAndroid(url);

String _apkFilePath = _apkFile.path;

if (_apkFilePath.isEmpty) {

print('make sure the apk file is set');

return;

}

InstallPlugin.installApk(_apkFilePath, Config.APP_ID)

  .then((result) {

print('install apk $result');

}).catchError((error) {

print('install apk error: $error');

});

}



Here I use`install_plugin: ^2.0.1`,The plug-in works normally on Android, but Apple First the newspaper



[!] Unable to determine Swift version for the following pods:

install_plugin does not specify a Swift version and none of the targets (Runner) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.

Xcode:

Interview review notes

This information will be published on blogs and forums since the spring recruit. Collect high-quality interview questions in Android Development on the website, and then find the best solution throughout the network. Each interview question is a 100% real question + the best answer. Package knowledge context + many details.
You can save the time of searching information on the Internet to learn, and you can also share it with your friends to learn together.
**[CodeChina open source project: Android learning notes summary + mobile architecture Video + big factory interview real questions + project actual combat source code](

)**

960 page Android Development Notes

1307 pages of Android development interview

It includes the questions asked in the interview of frontline Internet companies such as Tencent, Baidu, Xiaomi, Ali, LETV, meituan, 58, cheetah, 360, Sina and Sohu. Being familiar with the knowledge points listed in this article will greatly increase the probability of passing the first two rounds of technical interviews.

507 page Android development related source code analysis

As long as programmers, whether Java or Android, don't read the source code and only look at the API documents, they will just stay superficial, which is unfavorable to the establishment and completion of our knowledge system and the improvement of practical technology.

What can really exercise your ability is to read the source code directly, not only limited to reading the source code of major systems, but also various excellent open source libraries.

This article has been Tencent CODING open source hosting project: Android learning notes summary + mobile architecture Video + big factory interview real questions + project actual combat source code Collection, self-study resources and series of articles are continuously updated
I document, it just stays superficial, which is unfavorable to the establishment and perfection of our knowledge system and the improvement of practical technology.

What can really exercise your ability is to read the source code directly, not only limited to reading the source code of major systems, but also various excellent open source libraries.

[external chain picture transferring... (img-btRGyyuf-1631250933155)]

This article has been Tencent CODING open source hosting project: Android learning notes summary + mobile architecture Video + big factory interview real questions + project actual combat source code Collection, self-study resources and series of articles are continuously updated

Keywords: iOS Android Design Pattern Programmer Flutter

Added by Archangel915 on Sat, 20 Nov 2021 10:35:25 +0200