DirectorySelection
Content
com.example.android.directoryselection
true
androidx.appcompat:appcompat:1.0.2
androidx.recyclerview:recyclerview:1.0.0
21
28
PUBLISHED
Content
Android
Java
Mobile
INTERMEDIATE
screenshots/web-icon.png
screenshots/screenshot-1.png
screenshots/screenshot-2.png
screenshots/screenshot-3.png
android.content.ContentResolver
android.provider.DocumentsContract
directoryEntries = new ArrayList<>();
while (childCursor.moveToNext()) {
Log.d(TAG, "found child=" + childCursor.getString(0) + ", mime=" + childCursor
.getString(1));
DirectoryEntry entry = new DirectoryEntry();
entry.fileName = childCursor.getString(0);
entry.mimeType = childCursor.getString(1);
directoryEntries.add(entry);
}
mAdapter.setDirectoryEntries(directoryEntries);
mAdapter.notifyDataSetChanged();
} finally {
closeQuietly(childCursor);
}
}
```
Also, the new [createDocument()][8] method lets you create new documents or directories
anywhere under the subtree.
This example creates a new directory by following code:
```java
ContentResolver contentResolver = getActivity().getContentResolver();
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(uri,
DocumentsContract.getTreeDocumentId(uri));
Uri directoryUri = DocumentsContract
.createDocument(contentResolver, docUri, Document.MIME_TYPE_DIR, directoryName);
```
[1]: https://developer.android.com/about/versions/android-5.0.html#Storage
[2]: https://developer.android.com/guide/topics/providers/document-provider.html
[3]: https://developer.android.com/reference/android/content/Intent.html#ACTION_OPEN_DOCUMENT_TREE
[4]: https://developer.android.com/reference/android/provider/DocumentsProvider.html
[5]: https://developer.android.com/reference/android/provider/DocumentsContract.html#buildChildDocumentsUriUsingTree(android.net.Uri%2C%20java.lang.String)
[6]: https://developer.android.com/reference/android/provider/DocumentsContract.html#buildDocumentUriUsingTree(android.net.Uri%2C%20java.lang.String)
[7]: https://developer.android.com/reference/android/content/ContentResolver.html#query(android.net.Uri%2C%20java.lang.String%5B%5D%2C%20java.lang.String%2C%20java.lang.String%5B%5D%2C%20java.lang.String)
[8]: https://developer.android.com/reference/android/provider/DocumentsContract.html#createDocument(android.content.ContentResolver%2C%20android.net.Uri%2C%20java.lang.String%2C%20java.lang.String)
]]>