install method
安装APK(仅 Android)
Implementation
Future<InstallResult> install() async {
_ensureAndroid();
_ensureInitialized();
if (statusNotifier.value != DownloadStatus.finished || _savePath == null) {
_emit(UpgraderEventType.installError, '文件未下载完成,无法安装', {
'status': statusNotifier.value.name,
});
return const InstallResult(
InstallStatus.fileNotFound,
message: 'The APK has not finished downloading.',
);
}
_emit(UpgraderEventType.installStart, '准备安装 APK');
try {
final result = await TinyUpgraderPlatform.instance.installApk(_savePath!);
if (result.installerLaunched) {
_emit(UpgraderEventType.installIntentLaunched, 'APK 安装器已启动');
} else {
_emit(UpgraderEventType.installError, '未能启动 APK 安装器', {
'status': result.status.name,
'message': result.message,
});
}
return result;
} catch (error) {
_emit(UpgraderEventType.installError, '安装失败', {
'error': error.toString(),
});
_safeErrorCallback(error);
return InstallResult(InstallStatus.failed, message: error.toString());
}
}