android.provider.DocumentsContract.Document#FLAG_SUPPORTS_WRITE源码实例Demo

下面列出了android.provider.DocumentsContract.Document#FLAG_SUPPORTS_WRITE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: droidddle   文件: LocalStorageProvider.java
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
}
 
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
}
 
源代码3 项目: qiniu-lab-android   文件: LocalStorageProvider.java
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
}
 
源代码4 项目: droid-stealth   文件: LocalStorageProvider.java
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
}
 
源代码5 项目: Effects-Pro   文件: LocalStorageProvider.java
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
}
 
源代码6 项目: filechooser   文件: LocalStorageProvider.java
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
}
 
源代码7 项目: secrecy   文件: LocalStorageProvider.java
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
}
 
源代码8 项目: Readily   文件: LocalStorageProvider.java
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
}
 
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;
}
 
源代码10 项目: storage-samples   文件: MyCloudProvider.java
/**
 * 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);
}
 
源代码11 项目: android-StorageProvider   文件: MyCloudProvider.java
/**
 * 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);
}