mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-04-21 16:01:58 +00:00
refactor: update AndroidManifest and MainActivity for APK installation; remove flutter_app_installer dependency
This commit is contained in:
parent
c558c08376
commit
d250c08424
7 changed files with 65 additions and 22 deletions
|
|
@ -47,15 +47,17 @@
|
||||||
<data android:scheme="mangayomi" />
|
<data android:scheme="mangayomi" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
android:authorities="${applicationId}.fileProvider"
|
android:authorities="com.kodjodevf.mangayomi.fileprovider"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:grantUriPermissions="true">
|
android:grantUriPermissions="true">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/file_paths" />
|
android:resource="@xml/file_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<!-- Don't delete the meta-data below.
|
<!-- Don't delete the meta-data below.
|
||||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||||
<meta-data
|
<meta-data
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,11 @@ import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
import io.flutter.plugin.common.StandardMethodCodec
|
import io.flutter.plugin.common.StandardMethodCodec
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
|
import android.net.Uri
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class MainActivity: FlutterActivity() {
|
class MainActivity: FlutterActivity() {
|
||||||
|
|
||||||
|
|
@ -32,5 +37,38 @@ class MainActivity: FlutterActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MethodChannel(
|
||||||
|
flutterEngine.dartExecutor.binaryMessenger,
|
||||||
|
"com.kodjodevf.mangayomi.apk_install",
|
||||||
|
StandardMethodCodec.INSTANCE,
|
||||||
|
flutterEngine.dartExecutor.binaryMessenger.makeBackgroundTaskQueue()
|
||||||
|
).setMethodCallHandler { call, result ->
|
||||||
|
when (call.method) {
|
||||||
|
"installApk" -> {
|
||||||
|
val filePath = call.argument<String>("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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ subprojects {
|
||||||
if (project.plugins.hasPlugin("com.android.application") ||
|
if (project.plugins.hasPlugin("com.android.application") ||
|
||||||
project.plugins.hasPlugin("com.android.library")) {
|
project.plugins.hasPlugin("com.android.library")) {
|
||||||
project.android {
|
project.android {
|
||||||
compileSdkVersion 34
|
compileSdkVersion 35
|
||||||
buildToolsVersion "34.0.0"
|
buildToolsVersion "34.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -218,9 +218,7 @@ async function parseEpubChapter(bookName, url, headers, chapterTitle) {
|
||||||
await File(p.join(tmpDirectory.path, ".nomedia")).create();
|
await File(p.join(tmpDirectory.path, ".nomedia")).create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final file = File(
|
final file = File(p.join(tmpDirectory.path, "$bookName.epub"));
|
||||||
p.join(tmpDirectory.path, "$bookName.epub"),
|
|
||||||
);
|
|
||||||
if (await file.exists()) {
|
if (await file.exists()) {
|
||||||
return await file.readAsBytes();
|
return await file.readAsBytes();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:flutter/material.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_qjs/quickjs/ffi.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
@ -143,8 +145,7 @@ class _DownloadFileScreenState extends ConsumerState<DownloadFileScreen> {
|
||||||
if (!status.isGranted) {
|
if (!status.isGranted) {
|
||||||
await Permission.requestInstallPackages.request();
|
await Permission.requestInstallPackages.request();
|
||||||
}
|
}
|
||||||
final FlutterAppInstaller appInstaller = FlutterAppInstaller();
|
await ApkInstaller.installApk(file.path);
|
||||||
await appInstaller.installApk(filePath: file.path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _launchInBrowser(Uri url) async {
|
Future<void> _launchInBrowser(Uri url) async {
|
||||||
|
|
@ -153,3 +154,16 @@ class _DownloadFileScreenState extends ConsumerState<DownloadFileScreen> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ApkInstaller {
|
||||||
|
static const _platform = MethodChannel('com.kodjodevf.mangayomi.apk_install');
|
||||||
|
static Future<void> installApk(String filePath) async {
|
||||||
|
try {
|
||||||
|
await _platform.invokeMethod('installApk', {'filePath': filePath});
|
||||||
|
} catch (e) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
log("Erreur d'installation : $e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -539,14 +539,6 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
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:
|
flutter_cache_manager:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,6 @@ dependencies:
|
||||||
win32: ^5.10.1
|
win32: ^5.10.1
|
||||||
protobuf: ^4.0.0
|
protobuf: ^4.0.0
|
||||||
device_info_plus: ^11.3.3
|
device_info_plus: ^11.3.3
|
||||||
flutter_app_installer: ^1.0.0
|
|
||||||
marquee: ^2.2.3
|
marquee: ^2.2.3
|
||||||
epubx:
|
epubx:
|
||||||
path: ./epubx
|
path: ./epubx
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue