Поскольку ваша таблица DataTable всегда имеет одинаковые столбцы (они не изменяются для любой строки), вам нужно только один раз проверить имя столбца.
if (table.Columns.Contains("donkey"))
{
foreach ...
}
это дает мне файлы документов, которые мне нужны, и получает помощь от одного из стеков по ссылкам потока.
public void getDocumentspath(){
listOfAllDocuments = new ArrayList<String>();
Cursor cursor;
String root_sd = Environment.getExternalStorageDirectory().toString();
String pdf = MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf");
String doc = MimeTypeMap.getSingleton().getMimeTypeFromExtension("doc");
String docx = MimeTypeMap.getSingleton().getMimeTypeFromExtension("docx");
String xls = MimeTypeMap.getSingleton().getMimeTypeFromExtension("xls");
String xlsx = MimeTypeMap.getSingleton().getMimeTypeFromExtension("xlsx");
String ppt = MimeTypeMap.getSingleton().getMimeTypeFromExtension("ppt");
String pptx = MimeTypeMap.getSingleton().getMimeTypeFromExtension("pptx");
String txt = MimeTypeMap.getSingleton().getMimeTypeFromExtension("txt");
String rtx = MimeTypeMap.getSingleton().getMimeTypeFromExtension("rtx");
String rtf = MimeTypeMap.getSingleton().getMimeTypeFromExtension("rtf");
String html = MimeTypeMap.getSingleton().getMimeTypeFromExtension("html");
String css = MimeTypeMap.getSingleton().getMimeTypeFromExtension("css");
// String js = MimeTypeMap.getSingleton().getMimeTypeFromExtension("js");
//Table
Uri table = MediaStore.Files.getContentUri("external");
//Column
String[] column = {MediaStore.Files.FileColumns.DATA};
//Where
String where = MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?"
+" OR " +MediaStore.Files.FileColumns.MIME_TYPE + "=?";
//args
String[] args = new String[]{pdf,doc,docx,xls,xlsx,ppt,pptx,txt,rtx,rtf,html,css};
Cursor fileCursor = getContentResolver().query(table, column, where, args, null);
int count = fileCursor.getCount();
//Create an array to store path to all the documents
String[] arrPath = new String[count];
for (int i = 0; i < count; i++) {
fileCursor.moveToPosition(i);
int dataColumnIndex = fileCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
//Store the path of the document
arrPath[i] = fileCursor.getString(dataColumnIndex);
Bitmap b = ((BitmapDrawable) ResourcesCompat.getDrawable(this.getResources(), R.drawable.documentfile, null)).getBitmap();
bitmap.add(b);
Log.i("PATH", arrPath[i]);
listOfAllDocuments.add(arrPath[i]);
}
}