|
|
@ -97,11 +97,11 @@ object DocumentUtils { |
|
|
|
|
|
|
|
|
|
|
|
fun listFiles(context: Context, uri: Uri): ArrayList<DocItem> { |
|
|
|
fun listFiles(context: Context, uri: Uri): ArrayList<DocItem> { |
|
|
|
val docList = arrayListOf<DocItem>() |
|
|
|
val docList = arrayListOf<DocItem>() |
|
|
|
var c: Cursor? = null |
|
|
|
var cursor: Cursor? = null |
|
|
|
try { |
|
|
|
try { |
|
|
|
val childrenUri = DocumentsContract |
|
|
|
val childrenUri = DocumentsContract |
|
|
|
.buildChildDocumentsUriUsingTree(uri, DocumentsContract.getDocumentId(uri)) |
|
|
|
.buildChildDocumentsUriUsingTree(uri, DocumentsContract.getDocumentId(uri)) |
|
|
|
c = context.contentResolver.query( |
|
|
|
cursor = context.contentResolver.query( |
|
|
|
childrenUri, arrayOf( |
|
|
|
childrenUri, arrayOf( |
|
|
|
DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
|
|
|
DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
|
|
|
DocumentsContract.Document.COLUMN_DISPLAY_NAME, |
|
|
|
DocumentsContract.Document.COLUMN_DISPLAY_NAME, |
|
|
@ -110,29 +110,30 @@ object DocumentUtils { |
|
|
|
DocumentsContract.Document.COLUMN_MIME_TYPE |
|
|
|
DocumentsContract.Document.COLUMN_MIME_TYPE |
|
|
|
), null, null, DocumentsContract.Document.COLUMN_DISPLAY_NAME |
|
|
|
), null, null, DocumentsContract.Document.COLUMN_DISPLAY_NAME |
|
|
|
) |
|
|
|
) |
|
|
|
c?.let { |
|
|
|
cursor?.let { |
|
|
|
val ici = c.getColumnIndex(DocumentsContract.Document.COLUMN_DOCUMENT_ID) |
|
|
|
val ici = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DOCUMENT_ID) |
|
|
|
val nci = c.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME) |
|
|
|
val nci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME) |
|
|
|
val sci = c.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE) |
|
|
|
val sci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE) |
|
|
|
val mci = c.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE) |
|
|
|
val mci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE) |
|
|
|
val dci = c.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED) |
|
|
|
val dci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED) |
|
|
|
if (c.moveToFirst()) { |
|
|
|
if (cursor.moveToFirst()) { |
|
|
|
do { |
|
|
|
do { |
|
|
|
val item = DocItem( |
|
|
|
val item = DocItem( |
|
|
|
name = c.getString(nci), |
|
|
|
name = cursor.getString(nci), |
|
|
|
attr = c.getString(mci), |
|
|
|
attr = cursor.getString(mci), |
|
|
|
size = c.getLong(sci), |
|
|
|
size = cursor.getLong(sci), |
|
|
|
date = Date(c.getLong(dci)), |
|
|
|
date = Date(cursor.getLong(dci)), |
|
|
|
uri = DocumentsContract.buildDocumentUriUsingTree(uri, c.getString(ici)) |
|
|
|
uri = DocumentsContract |
|
|
|
|
|
|
|
.buildDocumentUriUsingTree(uri, cursor.getString(ici)) |
|
|
|
) |
|
|
|
) |
|
|
|
docList.add(item) |
|
|
|
docList.add(item) |
|
|
|
} while (c.moveToNext()) |
|
|
|
} while (cursor.moveToNext()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
e.printOnDebug() |
|
|
|
e.printOnDebug() |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
c?.close() |
|
|
|
cursor?.close() |
|
|
|
} |
|
|
|
} |
|
|
|
return docList |
|
|
|
return docList |
|
|
|
} |
|
|
|
} |
|
|
|