mirror of
https://github.com/localsend/localsend.git
synced 2026-08-07 07:14:52 +00:00
fix: get correct downloads directory
This commit is contained in:
@@ -7,6 +7,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import android.provider.DocumentsContract
|
||||
import android.provider.Settings
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
@@ -79,11 +80,21 @@ class MainActivity : FlutterActivity() {
|
||||
result.success(isAnimationsEnabled())
|
||||
}
|
||||
|
||||
"getDownloadsDirectory" -> {
|
||||
result.success(getDownloadsDirectory())
|
||||
}
|
||||
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Absolute path of the shared "Download" directory (usually /storage/emulated/0/Download).
|
||||
@Suppress("DEPRECATION")
|
||||
private fun getDownloadsDirectory(): String {
|
||||
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath
|
||||
}
|
||||
|
||||
private fun isAnimationsEnabled() : Boolean {
|
||||
return Settings.Global.getFloat(this.getContentResolver(),
|
||||
Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f) != 0.0f;
|
||||
|
||||
@@ -39,6 +39,16 @@ Future<List<FileInfo>?> pickFilesAndroid() async {
|
||||
return result.map((e) => FileInfoMapper.fromJson((e as Map).cast<String, dynamic>())).toList();
|
||||
}
|
||||
|
||||
/// Returns the global "Download" directory, e.g. /storage/emulated/0/Download.
|
||||
Future<String?> getDownloadsDirectoryAndroid() async {
|
||||
try {
|
||||
return await _methodChannel.invokeMethod<String>('getDownloadsDirectory');
|
||||
} catch (e) {
|
||||
_logger.warning('Could not get downloads directory', e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> getSystemAnimationsStatusAndroid() async {
|
||||
return await _methodChannel.invokeMethod('isAnimationsEnabled') ?? true;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import 'dart:io' show Directory, Platform;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:localsend_app/util/native/channel/android_channel.dart';
|
||||
import 'package:path_provider/path_provider.dart' as path;
|
||||
|
||||
Future<String> getDefaultDestinationDirectory() async {
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.android:
|
||||
final dir = await path.getDownloadsDirectory();
|
||||
return dir?.path ?? '/storage/emulated/0/Download';
|
||||
return await getDownloadsDirectoryAndroid() ?? '/storage/emulated/0/Download';
|
||||
case TargetPlatform.iOS:
|
||||
return (await path.getApplicationDocumentsDirectory()).path;
|
||||
case TargetPlatform.linux:
|
||||
|
||||
Reference in New Issue
Block a user