From d250c084249bb25d8fdebe80fe7f6c5ef99dddd3 Mon Sep 17 00:00:00 2001 From: Moustapha Kodjo Amadou <107993382+kodjodevf@users.noreply.github.com> Date: Fri, 9 May 2025 18:38:23 +0100 Subject: [PATCH] refactor: update AndroidManifest and MainActivity for APK installation; remove flutter_app_installer dependency --- android/app/src/main/AndroidManifest.xml | 12 +++--- .../com/kodjodevf/mangayomi/MainActivity.kt | 38 +++++++++++++++++++ android/build.gradle | 2 +- lib/eval/javascript/utils.dart | 4 +- .../about/providers/download_file_screen.dart | 22 +++++++++-- pubspec.lock | 8 ---- pubspec.yaml | 1 - 7 files changed, 65 insertions(+), 22 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index c8927d18..7e342774 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -47,15 +47,17 @@ + - + + + when (call.method) { + "installApk" -> { + val filePath = call.argument("filePath") + installApk(filePath) + result.success(null) + } + else -> { + result.notImplemented() + } + } + } + } + + private fun installApk(filePath: String?) { + if (filePath == null) return + val file = File(filePath) + val intent = Intent(Intent.ACTION_VIEW) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + val apkUri: Uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION + FileProvider.getUriForFile(this, "$packageName.fileprovider", file) + } else { + Uri.fromFile(file) + } + intent.setDataAndType(apkUri, "application/vnd.android.package-archive") + startActivity(intent) } } diff --git a/android/build.gradle b/android/build.gradle index e7c821a4..695f504f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -12,7 +12,7 @@ subprojects { if (project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.library")) { project.android { - compileSdkVersion 34 + compileSdkVersion 35 buildToolsVersion "34.0.0" } } diff --git a/lib/eval/javascript/utils.dart b/lib/eval/javascript/utils.dart index b5e6147e..49d0a790 100644 --- a/lib/eval/javascript/utils.dart +++ b/lib/eval/javascript/utils.dart @@ -218,9 +218,7 @@ async function parseEpubChapter(bookName, url, headers, chapterTitle) { await File(p.join(tmpDirectory.path, ".nomedia")).create(); } } - final file = File( - p.join(tmpDirectory.path, "$bookName.epub"), - ); + final file = File(p.join(tmpDirectory.path, "$bookName.epub")); if (await file.exists()) { return await file.readAsBytes(); } diff --git a/lib/modules/more/about/providers/download_file_screen.dart b/lib/modules/more/about/providers/download_file_screen.dart index 95beb72b..00b449d4 100644 --- a/lib/modules/more/about/providers/download_file_screen.dart +++ b/lib/modules/more/about/providers/download_file_screen.dart @@ -1,9 +1,11 @@ import 'dart:async'; +import 'dart:developer'; import 'dart:io'; - +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_app_installer/flutter_app_installer.dart'; +// import 'package:flutter_app_installer/flutter_app_installer.dart'; import 'package:flutter_qjs/quickjs/ffi.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:http/http.dart' as http; @@ -143,8 +145,7 @@ class _DownloadFileScreenState extends ConsumerState { if (!status.isGranted) { await Permission.requestInstallPackages.request(); } - final FlutterAppInstaller appInstaller = FlutterAppInstaller(); - await appInstaller.installApk(filePath: file.path); + await ApkInstaller.installApk(file.path); } Future _launchInBrowser(Uri url) async { @@ -153,3 +154,16 @@ class _DownloadFileScreenState extends ConsumerState { } } } + +class ApkInstaller { + static const _platform = MethodChannel('com.kodjodevf.mangayomi.apk_install'); + static Future installApk(String filePath) async { + try { + await _platform.invokeMethod('installApk', {'filePath': filePath}); + } catch (e) { + if (kDebugMode) { + log("Erreur d'installation : $e"); + } + } + } +} diff --git a/pubspec.lock b/pubspec.lock index c3bcf221..4d6c381f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -539,14 +539,6 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_app_installer: - dependency: "direct main" - description: - name: flutter_app_installer - sha256: "2243cf0e58d6f126420a800fcd06e7c5b3a048c5551914a006b29575125d8dc0" - url: "https://pub.dev" - source: hosted - version: "1.0.1" flutter_cache_manager: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 84b21cf8..c4234b4b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -83,7 +83,6 @@ dependencies: win32: ^5.10.1 protobuf: ^4.0.0 device_info_plus: ^11.3.3 - flutter_app_installer: ^1.0.0 marquee: ^2.2.3 epubx: path: ./epubx