mirror of
https://github.com/dstark5/Openlib.git
synced 2025-09-19 13:33:35 +08:00
added open with feature
This commit is contained in:
@ -1,13 +1,58 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
// import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:openlib/state/state.dart' show dbProvider, myLibraryProvider;
|
||||
|
||||
Future<String> get getAppDirectoryPath async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
return directory.path;
|
||||
if (Platform.isAndroid) {
|
||||
final directory = await getExternalStorageDirectory();
|
||||
return directory!.path;
|
||||
// // final path = '/storage/emulated/0/Openlib';
|
||||
// print(directory.path);
|
||||
// // File(directory.path).copySync(newPath);
|
||||
// return '/storage/emulated/0/Openlib';
|
||||
} else {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
return directory.path;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> moveFilesToAndroidInternalStorage() async {
|
||||
try {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
final directoryExternal = await getExternalStorageDirectory();
|
||||
List<FileSystemEntity> files = Directory(directory.path).listSync();
|
||||
for (var element in files) {
|
||||
if ((element.path.contains('pdf')) || element.path.contains('epub')) {
|
||||
String fileName = element.path.split('/').last;
|
||||
File file = File(element.path);
|
||||
file.copySync('${directoryExternal!.path}/$fileName');
|
||||
file.deleteSync();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Future<void> getStoragePermissionAndroid() async {
|
||||
// if (Platform.isAndroid) {
|
||||
// print("hi");
|
||||
// if (await Permission.storage.status.isGranted ||
|
||||
// await Permission.manageExternalStorage.status.isGranted) {
|
||||
// final storagePermission = await Permission.storage.request().isGranted;
|
||||
// final manageStoragePermission =
|
||||
// await Permission.manageExternalStorage.request().isGranted;
|
||||
// print(storagePermission || manageStoragePermission);
|
||||
// if (storagePermission || manageStoragePermission) {
|
||||
// await openAppSettings();
|
||||
// print(storagePermission || manageStoragePermission);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<bool> isFileExists(String filePath) async {
|
||||
return await File(filePath).exists();
|
||||
}
|
||||
|
Reference in New Issue
Block a user