Java Code Examples for android.provider.DocumentsContract.Document#MIME_TYPE_DIR

The following examples show how to use android.provider.DocumentsContract.Document#MIME_TYPE_DIR . 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: AppStorageProvider.java    From JPPF with Apache License 2.0 6 votes vote down vote up
/**
 * Add a row in the specified cursor for the specified file.
 * @param child the file for which to add a row.
 * @param cursor the cursor to add a row to.
 */
private void createRowForChild(File child, MatrixCursor cursor) {
  MatrixCursor.RowBuilder row = cursor.newRow();
  String type = getContext().getContentResolver().getType(Uri.fromFile(child));
  Log.v(LOG_TAG, "createRowForChild(child=" + child + ") type=" + type);
  if (type == null) type = child.isDirectory() ? Document.MIME_TYPE_DIR : "application/octet-stream";
  int flags = child.isDirectory()
    ? /*Document.FLAG_DIR_PREFERS_GRID |*/ Document.FLAG_DIR_PREFERS_LAST_MODIFIED | Document.FLAG_DIR_SUPPORTS_CREATE
    : /*Document.FLAG_SUPPORTS_WRITE*/ 0;
  row.add(Document.COLUMN_FLAGS, flags);
  row.add(Document.COLUMN_DISPLAY_NAME, child.getName());
  row.add(Document.COLUMN_DOCUMENT_ID, getDocumentId(child));
  row.add(Document.COLUMN_MIME_TYPE, type);
  row.add(Document.COLUMN_SIZE, child.isDirectory() ? child.getTotalSpace() - child.getFreeSpace() : child.length());
  row.add(Document.COLUMN_LAST_MODIFIED, null);
}
 
Example 2
Source File: LocalStorageProvider.java    From droidddle with Apache License 2.0 6 votes vote down vote up
@Override
public String getDocumentType(final String documentId) throws FileNotFoundException {
    File file = new File(documentId);
    if (file.isDirectory())
        return Document.MIME_TYPE_DIR;
    // From FileProvider.getType(Uri)
    final int lastDot = file.getName().lastIndexOf('.');
    if (lastDot >= 0) {
        final String extension = file.getName().substring(lastDot + 1);
        final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mime != null) {
            return mime;
        }
    }
    return "application/octet-stream";
}
 
Example 3
Source File: LocalStorageProvider.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String getDocumentType(final String documentId) throws FileNotFoundException {
    File file = new File(documentId);
    if (file.isDirectory())
        return Document.MIME_TYPE_DIR;
    // From FileProvider.getType(Uri)
    final int lastDot = file.getName().lastIndexOf('.');
    if (lastDot >= 0) {
        final String extension = file.getName().substring(lastDot + 1);
        final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mime != null) {
            return mime;
        }
    }
    return "application/octet-stream";
}
 
Example 4
Source File: LocalStorageProvider.java    From qiniu-lab-android with MIT License 6 votes vote down vote up
@Override
public String getDocumentType(final String documentId) throws FileNotFoundException {
    File file = new File(documentId);
    if (file.isDirectory())
        return Document.MIME_TYPE_DIR;
    // From FileProvider.getType(Uri)
    final int lastDot = file.getName().lastIndexOf('.');
    if (lastDot >= 0) {
        final String extension = file.getName().substring(lastDot + 1);
        final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mime != null) {
            return mime;
        }
    }
    return "application/octet-stream";
}
 
Example 5
Source File: LocalStorageProvider.java    From droid-stealth with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDocumentType(final String documentId) throws FileNotFoundException {
    File file = new File(documentId);
    if (file.isDirectory())
        return Document.MIME_TYPE_DIR;
    // From FileProvider.getType(Uri)
    final int lastDot = file.getName().lastIndexOf('.');
    if (lastDot >= 0) {
        final String extension = file.getName().substring(lastDot + 1);
        final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mime != null) {
            return mime;
        }
    }
    return "application/octet-stream";
}
 
Example 6
Source File: LocalStorageProvider.java    From Effects-Pro with MIT License 6 votes vote down vote up
@Override
public String getDocumentType(final String documentId) throws FileNotFoundException {
	File file = new File(documentId);
	if (file.isDirectory())
		return Document.MIME_TYPE_DIR;
	// From FileProvider.getType(Uri)
	final int lastDot = file.getName().lastIndexOf('.');
	if (lastDot >= 0) {
		final String extension = file.getName().substring(lastDot + 1);
		final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
		if (mime != null) {
			return mime;
		}
	}
	return "application/octet-stream";
}
 
Example 7
Source File: LocalStorageProvider.java    From filechooser with MIT License 6 votes vote down vote up
@Override
public String getDocumentType(final String documentId) throws FileNotFoundException {
    File file = new File(documentId);
    if (file.isDirectory())
        return Document.MIME_TYPE_DIR;
    // From FileProvider.getType(Uri)
    final int lastDot = file.getName().lastIndexOf('.');
    if (lastDot >= 0) {
        final String extension = file.getName().substring(lastDot + 1);
        final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mime != null) {
            return mime;
        }
    }
    return "application/octet-stream";
}
 
Example 8
Source File: LocalStorageProvider.java    From secrecy with Apache License 2.0 6 votes vote down vote up
@Override
public String getDocumentType(final String documentId) throws FileNotFoundException {
    File file = new File(documentId);
    if (file.isDirectory())
        return Document.MIME_TYPE_DIR;
    // From FileProvider.getType(Uri)
    final int lastDot = file.getName().lastIndexOf('.');
    if (lastDot >= 0) {
        final String extension = file.getName().substring(lastDot + 1);
        final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mime != null) {
            return mime;
        }
    }
    return "application/octet-stream";
}
 
Example 9
Source File: LocalStorageProvider.java    From Readily with MIT License 6 votes vote down vote up
@Override
public String getDocumentType(final String documentId) throws FileNotFoundException {
    File file = new File(documentId);
    if (file.isDirectory())
        return Document.MIME_TYPE_DIR;
    // From FileProvider.getType(Uri)
    final int lastDot = file.getName().lastIndexOf('.');
    if (lastDot >= 0) {
        final String extension = file.getName().substring(lastDot + 1);
        final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mime != null) {
            return mime;
        }
    }
    return "application/octet-stream";
}
 
Example 10
Source File: MyCloudProvider.java    From storage-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Get a file's MIME type
 *
 * @param file the File object whose type we want
 * @return the MIME type of the file
 */
private static String getTypeForFile(File file) {
    if (file.isDirectory()) {
        return Document.MIME_TYPE_DIR;
    } else {
        return getTypeForName(file.getName());
    }
}
 
Example 11
Source File: DocumentMetadata.java    From samba-documents-provider with GNU General Public License v3.0 5 votes vote down vote up
public String getMimeType() {
  switch (mEntry.getType()) {
    case DirectoryEntry.FILE_SHARE:
    case DirectoryEntry.WORKGROUP:
    case DirectoryEntry.SERVER:
    case DirectoryEntry.DIR:
      return Document.MIME_TYPE_DIR;

    case DirectoryEntry.LINK:
    case DirectoryEntry.COMMS_SHARE:
    case DirectoryEntry.IPC_SHARE:
    case DirectoryEntry.PRINTER_SHARE:
      throw new UnsupportedOperationException(
          "Unsupported type of Samba directory entry " + mEntry.getType());

    case DirectoryEntry.FILE:
      final String ext = getExtension(mEntry.getName());
      if (ext == null) {
        return GENERIC_MIME_TYPE;
      }

      final String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
      return (mimeType == null) ? GENERIC_MIME_TYPE : mimeType;
  }

  throw new IllegalStateException("Should never reach here.");
}
 
Example 12
Source File: MyCloudProvider.java    From android-StorageProvider with Apache License 2.0 5 votes vote down vote up
/**
 * Get a file's MIME type
 *
 * @param file the File object whose type we want
 * @return the MIME type of the file
 */
private static String getTypeForFile(File file) {
    if (file.isDirectory()) {
        return Document.MIME_TYPE_DIR;
    } else {
        return getTypeForName(file.getName());
    }
}