gpt4 book ai didi

android - 从手机获取所有文件的最佳方式?

转载 作者:行者123 更新时间:2023-11-29 14:14:18 26 4
gpt4 key购买 nike

我想获取除视频和图像和音频文件之外的所有类型的文档 pdf、xml、doc。

并显示包含名称、大小、日期和位置的列表。

       ContentResolver cr = context.getContentResolver();
Uri uri = MediaStore.Files.getContentUri("external");

// every column, although that is huge waste, you probably need
// BaseColumns.DATA (the path) only.
String[] projection = null;

// exclude media files, they would be here also.
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
String[] selectionArgs = null; // there is no ? in selection so null here

String sortOrder = null; // unordered
Cursor allNonMediaFiles = cr.query(uri, projection, selection, selectionArgs, sortOrder);

我正在使用此代码从移动设备获取文档,它可以工作吗?以及如何获取文档详细信息,如 uri、日期和名称。提前致谢。

最佳答案

试试这个:

File path;
ArrayList<String> pdf_paths=new ArrayList<String>();
ArrayList<String> pdf_names=new ArrayList<String>();
path = new File(Environment.getExternalStorageDirectory() + "");
searchFolderRecursive1(path);

private static void searchFolderRecursive1(File folder)
{
if (file.isFile())
{
//.pdf files
if(file.getName().contains(".pdf"))
{
file.getPath();
pdf_names.add(file.getName());
pdf_paths.add(file.getPath());
Log.e("pdf_paths", ""+pdf_names);
}
else if(file.getName().contains(".doc"))
{
file.getPath();
pdf_names.add(file.getName());
pdf_paths.add(file.getPath());
}
}
}

关于android - 从手机获取所有文件的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29384442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com