Я пробовал использовать MediaStore:
Код: Выделить всё
public static List GetFilesFromMediaStore(string[] fileExtensions)
{
var result = new List();
var uri = MediaStore.Files.GetContentUri("external");
var selection = string.Join(" OR ", fileExtensions.Select(ext => $"_data LIKE '%.{ext}'"));
string[] projection = {
MediaStore.Files.FileColumns.Data,
MediaStore.Files.FileColumns.DisplayName
};
using (var cursor = Android.App.Application.Context.ContentResolver.Query(uri, projection, selection, null, null))
{
if (cursor != null && cursor.MoveToFirst())
{
do
{
var filePath = cursor.GetString(cursor.GetColumnIndexOrThrow(MediaStore.Files.FileColumns.Data));
result.Add(filePath);
}
while (cursor.MoveToNext());
}
}
return result;
}
Код: Выделить всё
public static List GetFilesJavaIO(string rootPath)
{
var result = new List();
var rootDir = new Java.IO.File(rootPath);
if (!rootDir.Exists() || !rootDir.IsDirectory)
{
Debug.WriteLine($"Path is not a directory or doesn't exist: {rootPath}");
return result;
}
var filesAndDirs = rootDir.ListFiles();
if (filesAndDirs == null) return result;
foreach (var fileOrDir in filesAndDirs)
{
if (fileOrDir.IsDirectory)
{
// Рекурсивный вызов для подпапок
result.AddRange(GetFilesJavaIO(fileOrDir.AbsolutePath));
}
else if (fileOrDir.IsFile)
{
result.Add(fileOrDir.AbsolutePath);
}
}
return result;
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... es-on-maui