admin管理员组文章数量:1023136
I am doing android reader app on maui and stuck on auto finding fb2 and txt files. I've also pushed into storage png and jpg files and program finds it, but not fb2 and txt which are in the same directory. I've tried using MediaStore:
public static List<string> GetFilesFromMediaStore(string[] fileExtensions)
{
var result = new List<string>();
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;
}
and tried java.io:
public static List<string> GetFilesJavaIO(string rootPath)
{
var result = new List<string>();
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;
}
but nothing seems to work correctly
I am doing android reader app on maui and stuck on auto finding fb2 and txt files. I've also pushed into storage png and jpg files and program finds it, but not fb2 and txt which are in the same directory. I've tried using MediaStore:
public static List<string> GetFilesFromMediaStore(string[] fileExtensions)
{
var result = new List<string>();
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;
}
and tried java.io:
public static List<string> GetFilesJavaIO(string rootPath)
{
var result = new List<string>();
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;
}
but nothing seems to work correctly
本文标签: Trouble scanning android emulator for files on mauiStack Overflow
版权声明:本文标题:Trouble scanning android emulator for files on maui - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745560658a2156141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论