downloadAndInstallApk method
Future<bool>
downloadAndInstallApk({
- required String fileUrl,
- required String fileDirectory,
- required String fileName,
- bool isDeleteOriginalFile = true,
- String? explainContent,
- String? positiveText,
- String? negativeText,
- dynamic onDownloadingListener(
- double progress
- dynamic onCancelTagListener(
- String cancelTag
- OnStateChangeListener? onStateListener,
下载APK到沙盒目录下,并执行安装操作
仅支持Android
Implementation
Future<bool> downloadAndInstallApk({
required String fileUrl,
required String fileDirectory,
required String fileName,
bool isDeleteOriginalFile = true,
String? explainContent,
String? positiveText,
String? negativeText,
Function(double progress)? onDownloadingListener,
Function(String cancelTag)? onCancelTagListener,
OnStateChangeListener? onStateListener,
}) async {
if (defaultTargetPlatform != TargetPlatform.android) {
return false;
}
if (fileUrl.isEmpty || fileDirectory.isEmpty || fileName.isEmpty) {
debugPrint(
"EasyAppInstaller.downloadAndInstallApk: fileUrl/fileDirectory/fileName must not be empty!");
return false;
}
final arguments = <String, dynamic>{
"fileUrl": fileUrl,
"fileDirectory": fileDirectory,
"fileName": fileName,
"isDeleteOriginalFile": isDeleteOriginalFile,
"explainContent": explainContent,
"positiveText": positiveText,
"negativeText": negativeText,
};
if (onDownloadingListener != null ||
onCancelTagListener != null ||
onStateListener != null) {
_channel.setMethodCallHandler((call) async {
switch (call.method) {
case EasyAppInstallerConstant.methodDownloadProgress:
if (call.arguments is double && onDownloadingListener != null) {
onDownloadingListener((call.arguments as double));
}
break;
case EasyAppInstallerConstant.methodCancelTag:
if (call.arguments is String && onCancelTagListener != null) {
onCancelTagListener((call.arguments as String));
}
break;
case EasyAppInstallerConstant.methodDownloadState:
if (onStateListener != null && call.arguments != null) {
_handleDownloadState(call.arguments, onStateListener);
}
break;
}
});
}
try {
await _channel.invokeMethod("downloadAndInstallApk", arguments);
return true;
} catch (e) {
debugPrint("EasyAppInstaller.downloadAndInstallApk: $e");
return false;
}
}