diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 64bc9e233..faa4a7532 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -88,10 +88,8 @@ object DocumentUtils { val docList = arrayListOf() var c: Cursor? = null try { - val childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree( - uri, - DocumentsContract.getDocumentId(uri) - ) + val childrenUri = DocumentsContract + .buildChildDocumentsUriUsingTree(uri, DocumentsContract.getDocumentId(uri)) c = context.contentResolver.query( childrenUri, arrayOf( DocumentsContract.Document.COLUMN_DOCUMENT_ID, @@ -107,17 +105,18 @@ object DocumentUtils { val sci = c.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE) val mci = c.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE) val dci = c.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED) - c.moveToFirst() - do { - val item = DocItem( - name = c.getString(nci), - attr = c.getString(mci), - size = c.getLong(sci), - date = Date(c.getLong(dci)), - uri = DocumentsContract.buildDocumentUriUsingTree(uri, c.getString(ici)) - ) - docList.add(item) - } while (c.moveToNext()) + if (c.moveToFirst()) { + do { + val item = DocItem( + name = c.getString(nci), + attr = c.getString(mci), + size = c.getLong(sci), + date = Date(c.getLong(dci)), + uri = DocumentsContract.buildDocumentUriUsingTree(uri, c.getString(ici)) + ) + docList.add(item) + } while (c.moveToNext()) + } } } catch (e: Exception) { e.printStackTrace()