Java Code Examples for android.provider.DocumentsContract.Document#FLAG_SUPPORTS_WRITE
The following examples show how to use
android.provider.DocumentsContract.Document#FLAG_SUPPORTS_WRITE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalStorageProvider.java From droidddle with Apache License 2.0 | 6 votes |
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
Example 2
Source File: LocalStorageProvider.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
Example 3
Source File: LocalStorageProvider.java From qiniu-lab-android with MIT License | 6 votes |
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
Example 4
Source File: LocalStorageProvider.java From droid-stealth with GNU General Public License v2.0 | 6 votes |
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
Example 5
Source File: LocalStorageProvider.java From Effects-Pro with MIT License | 6 votes |
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
Example 6
Source File: LocalStorageProvider.java From filechooser with MIT License | 6 votes |
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
Example 7
Source File: LocalStorageProvider.java From secrecy with Apache License 2.0 | 6 votes |
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
Example 8
Source File: LocalStorageProvider.java From Readily with MIT License | 6 votes |
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
Example 9
Source File: SambaDocumentsProvider.java From samba-documents-provider with GNU General Public License v3.0 | 5 votes |
private Object[] getDocumentValues( String[] projection, DocumentMetadata metadata) { Object[] row = new Object[projection.length]; for (int i = 0; i < projection.length; ++i) { switch (projection[i]) { case Document.COLUMN_DOCUMENT_ID: row[i] = toDocumentId(metadata.getUri()); break; case Document.COLUMN_DISPLAY_NAME: row[i] = metadata.getDisplayName(); break; case Document.COLUMN_FLAGS: // Always assume it can write to it until the file operation fails. Windows 10 also does // the same thing. int flag = metadata.canCreateDocument() ? Document.FLAG_DIR_SUPPORTS_CREATE : 0; flag |= Document.FLAG_SUPPORTS_WRITE; flag |= Document.FLAG_SUPPORTS_DELETE; flag |= Document.FLAG_SUPPORTS_RENAME; flag |= Document.FLAG_SUPPORTS_REMOVE; flag |= Document.FLAG_SUPPORTS_MOVE; row[i] = flag; break; case Document.COLUMN_MIME_TYPE: row[i] = metadata.getMimeType(); break; case Document.COLUMN_SIZE: row[i] = metadata.getSize(); break; case Document.COLUMN_LAST_MODIFIED: row[i] = metadata.getLastModified(); break; case Document.COLUMN_ICON: row[i] = metadata.getIconResourceId(); break; } } return row; }
Example 10
Source File: MyCloudProvider.java From storage-samples with Apache License 2.0 | 4 votes |
/** * Add a representation of a file to a cursor. * * @param result the cursor to modify * @param docId the document ID representing the desired file (may be null if given file) * @param file the File object representing the desired file (may be null if given docID) * @throws java.io.FileNotFoundException */ private void includeFile(MatrixCursor result, String docId, File file) throws FileNotFoundException { if (docId == null) { docId = getDocIdForFile(file); } else { file = getFileForDocId(docId); } int flags = 0; if (file.isDirectory()) { // Request the folder to lay out as a grid rather than a list. This also allows a larger // thumbnail to be displayed for each image. // flags |= Document.FLAG_DIR_PREFERS_GRID; // Add FLAG_DIR_SUPPORTS_CREATE if the file is a writable directory. if (file.isDirectory() && file.canWrite()) { flags |= Document.FLAG_DIR_SUPPORTS_CREATE; } } else if (file.canWrite()) { // If the file is writable set FLAG_SUPPORTS_WRITE and // FLAG_SUPPORTS_DELETE flags |= Document.FLAG_SUPPORTS_WRITE; flags |= Document.FLAG_SUPPORTS_DELETE; } final String displayName = file.getName(); final String mimeType = getTypeForFile(file); if (mimeType.startsWith("image/")) { // Allow the image to be represented by a thumbnail rather than an icon flags |= Document.FLAG_SUPPORTS_THUMBNAIL; } final MatrixCursor.RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, docId); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SIZE, file.length()); row.add(Document.COLUMN_MIME_TYPE, mimeType); row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); row.add(Document.COLUMN_FLAGS, flags); // Add a custom icon row.add(Document.COLUMN_ICON, R.drawable.ic_launcher); }
Example 11
Source File: MyCloudProvider.java From android-StorageProvider with Apache License 2.0 | 4 votes |
/** * Add a representation of a file to a cursor. * * @param result the cursor to modify * @param docId the document ID representing the desired file (may be null if given file) * @param file the File object representing the desired file (may be null if given docID) * @throws java.io.FileNotFoundException */ private void includeFile(MatrixCursor result, String docId, File file) throws FileNotFoundException { if (docId == null) { docId = getDocIdForFile(file); } else { file = getFileForDocId(docId); } int flags = 0; if (file.isDirectory()) { // Request the folder to lay out as a grid rather than a list. This also allows a larger // thumbnail to be displayed for each image. // flags |= Document.FLAG_DIR_PREFERS_GRID; // Add FLAG_DIR_SUPPORTS_CREATE if the file is a writable directory. if (file.isDirectory() && file.canWrite()) { flags |= Document.FLAG_DIR_SUPPORTS_CREATE; } } else if (file.canWrite()) { // If the file is writable set FLAG_SUPPORTS_WRITE and // FLAG_SUPPORTS_DELETE flags |= Document.FLAG_SUPPORTS_WRITE; flags |= Document.FLAG_SUPPORTS_DELETE; } final String displayName = file.getName(); final String mimeType = getTypeForFile(file); if (mimeType.startsWith("image/")) { // Allow the image to be represented by a thumbnail rather than an icon flags |= Document.FLAG_SUPPORTS_THUMBNAIL; } final MatrixCursor.RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, docId); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SIZE, file.length()); row.add(Document.COLUMN_MIME_TYPE, mimeType); row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); row.add(Document.COLUMN_FLAGS, flags); // Add a custom icon row.add(Document.COLUMN_ICON, R.drawable.ic_launcher); }