nc-photos/app/lib/mobile/android/media_store.dart

45 lines
1.2 KiB
Dart
Raw Normal View History

2021-04-10 06:28:12 +02:00
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:nc_photos/exception.dart';
2021-04-10 06:28:12 +02:00
class MediaStore {
static Future<String> saveFileToDownload(
2021-07-23 22:05:57 +02:00
String fileName, Uint8List fileContent) async {
try {
return (await _channel
.invokeMethod<String>("saveFileToDownload", <String, dynamic>{
"fileName": fileName,
"content": fileContent,
}))!;
} on PlatformException catch (e) {
if (e.code == _exceptionCodePermissionError) {
throw PermissionException();
} else {
rethrow;
}
}
2021-07-23 22:05:57 +02:00
}
2021-04-10 06:28:12 +02:00
static Future<String> copyFileToDownload(
String toFileName, String fromFilePath) async {
try {
return (await _channel
.invokeMethod<String>("copyFileToDownload", <String, dynamic>{
"toFileName": toFileName,
"fromFilePath": fromFilePath,
}))!;
} on PlatformException catch (e) {
if (e.code == _exceptionCodePermissionError) {
throw PermissionException();
} else {
rethrow;
}
}
}
static const _exceptionCodePermissionError = "permissionError";
2021-09-15 08:58:06 +02:00
static const _channel = MethodChannel("com.nkming.nc_photos/media_store");
2021-04-10 06:28:12 +02:00
}