hui-z / flutter_install_plugin

A flutter plugin for install apk for android; and using url to go to app store for iOS.
MIT License
103 stars 111 forks source link

Error during APK update #77

Open Taiidzy opened 10 hours ago

Taiidzy commented 10 hours ago

An error occurs while updating the application.

Log: I/flutter ( 5284): Начинаем загрузку APK... I/flutter ( 5284): APK успешно загружен: /data/user/0/space.aniflim.aniflim/cache/update.apk I/flutter ( 5284): Загрузка завершена. Результат: true I/flutter ( 5284): Начинаем установку APK... I/flutter ( 5284): Начинаем установку APK: /data/user/0/space.aniflim.aniflim/cache/update.apk для пакета: space.aniflim.aniflim I/test ( 5284): onMethodCall:/data/user/0/space.aniflim.aniflim/cache/update.apk,null I/test ( 5284): getInstallAppIntent:33 I/test ( 5284): getInstallAppIntent:content://space.aniflim.aniflim.installFileProvider.install/cache_path/update.apk D/DecorView: onWindowFocusChanged hasWindowFocus false I/InstallPlugin( 5284): handleActivityResult(1024,1,Intent { (has extras) }) I/flutter ( 5284): install apk fail:Install Cancel I/flutter ( 5284): Установка завершена. W/aniflim.aniflim( 5284): Reducing the number of considered missed Gc histogram windows from 210 to 100 D/DecorView: onWindowFocusChanged hasWindowFocus true I/HandWritingStubImpl( 5284): refreshLastKeyboardType: 1 I/HandWritingStubImpl( 5284): getCurrentKeyboardType: 1

Function for downloading and installing APK:

static Future downloadAndInstallApk(BuildContext context) async { try { var appDocDir = await getTemporaryDirectory(); String savePath = '${appDocDir.path}/update.apk'; String fileUrl = "https://aniflim.space/app"; // Загрузка APK debugPrint('Начинаем загрузку APK...'); bool update = await downloadApk(savePath, fileUrl); debugPrint('Загрузка завершена. Результат: $update');

  // Установка APK
  if (update) {
    debugPrint('Начинаем установку APK...');
    await installApk(savePath);
    debugPrint('Установка завершена.');
  } else {
    debugPrint('Загрузка не удалась, установка не будет выполнена.');
  }
} catch (e) {
  debugPrint('Ошибка в процессе загрузки и установки APK: $e');
}

}

Taiidzy commented 10 hours ago

APK installation function:

static Future installApk(String savePath) async { try { PackageInfo packageInfo = await PackageInfo.fromPlatform(); String packageName = packageInfo.packageName;

  debugPrint("Начинаем установку APK: $savePath для пакета: $packageName");

  final res = await InstallPlugin.install(savePath);

  debugPrint("install apk ${res['isSuccess'] == true ? 'success' : 'fail:${res['errorMessage'] ?? ''}'}");

} catch (e) {
  debugPrint('Ошибка при установке APK: $e');
}

}