android.provider.DocumentsContract Java Examples

The following examples show how to use android.provider.DocumentsContract. 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: ImageUtil.java    From XposedNavigationBar with GNU General Public License v3.0 10 votes vote down vote up
/**
 * @param data
 * @return 图片路径
 */
public static String handleImageOnKitKat(Intent data) {
    String imagePath = "";
    Log.i(TAG, "handleImageOnKitKat: ");

    Uri uri = data.getData();
    if (DocumentsContract.isDocumentUri(MyApplication.getContext(), uri)) {
        //如果是document类型的uri,则通过document id处理
        String docId = DocumentsContract.getDocumentId(uri);
        if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
            String id = docId.split(":")[1];//解析出数字格式的ID
            String selection = MediaStore.Images.Media._ID + "=" + id;
            imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
        } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
            Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
            imagePath = getImagePath(contentUri, null);
        }
    } else if ("content".equalsIgnoreCase(uri.getScheme())) {
        //如果是content类型的uri,则使用普通的方式处理
        imagePath = getImagePath(uri, null);
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        //如果是file类型的uri,直接获取图片路径即可
        imagePath = uri.getPath();
    }
    return imagePath;
}
 
Example #2
Source File: FileUtils.java    From HeartBeat with Apache License 2.0 9 votes vote down vote up
@SuppressLint("NewApi")
public static String uriToPath(Context context, Uri uri) {
    boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        final String docId = DocumentsContract.getDocumentId(uri);
        Log.d("maxiee", "docID:" + docId);
        final String[] split = docId.split(":");
        final String type = split[0];
        Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        final String selection = "_id=?";
        final String[] selectionArgs = new String[] {split[1]};
        return getDataColumn(context, contentUri, selection, selectionArgs);
    } else if ("content".equalsIgnoreCase(uri.getScheme())){
        return getDataColumn(context, uri, null, null);
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }
    return null;
}
 
Example #3
Source File: FilePathHelper.java    From qcloud-sdk-android-samples with MIT License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private static String getKitKatPathFromMediaUri(Context context, Uri uri) {

    String imagePath = "";
    if (DocumentsContract.isDocumentUri(context, uri)) {
        String docId = DocumentsContract.getDocumentId(uri);
        if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
            //Log.d(TAG, uri.toString());
            String id = docId.split(":")[1];
            String selection = MediaStore.Images.Media._ID + "=" + id;

            imagePath = getImagePathFromMediaUri(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
        } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
            //Log.d(TAG, uri.toString());
            Uri contentUri = ContentUris.withAppendedId(
                    Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(docId));
            imagePath = getImagePathFromMediaUri(context, contentUri, null);
        }
    } else if ("content".equalsIgnoreCase(uri.getScheme())) {
        //Log.d(TAG, "content: " + uri.toString());
        imagePath = getImagePathFromMediaUri(context, uri, null);
    }
    return imagePath;
}
 
Example #4
Source File: VolumeInfo.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public @Nullable Intent buildBrowseIntentForUser(int userId) {
    final Uri uri;
    if (type == VolumeInfo.TYPE_PUBLIC && mountUserId == userId) {
        uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY, fsUuid);
    } else if (type == VolumeInfo.TYPE_EMULATED && isPrimary()) {
        uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY,
                DOCUMENT_ROOT_PRIMARY_EMULATED);
    } else {
        return null;
    }

    final Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(uri, DocumentsContract.Root.MIME_TYPE_ITEM);

    // note that docsui treats this as *force* show advanced. So sending
    // false permits advanced to be shown based on user preferences.
    intent.putExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, isPrimary());
    return intent;
}
 
Example #5
Source File: FileUtil.java    From Rumble with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("NewApi")
private static String getRealPathFromURI_API19(Context context, Uri uri){
    String filePath = "";
    String wholeID = DocumentsContract.getDocumentId(uri);

    // Split at colon, use second item in the array
    String id = wholeID.split(":")[1];

    String[] column = { MediaStore.Images.Media.DATA };

    // where id is equal to
    String sel = MediaStore.Images.Media._ID + "=?";

    Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            column, sel, new String[]{ id }, null);

    int columnIndex = cursor.getColumnIndex(column[0]);

    if (cursor.moveToFirst()) {
        filePath = cursor.getString(columnIndex);
    }
    cursor.close();
    return filePath;
}
 
Example #6
Source File: DocumentsContractApi21.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public static Uri[] listFiles(Context context, Uri self) {
    final ContentResolver resolver = context.getContentResolver();
    final Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(self,
            DocumentsContract.getDocumentId(self));
    final ArrayList<Uri> results = new ArrayList<Uri>();

    Cursor c = null;
    try {
        c = resolver.query(childrenUri, new String[] {
                DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null);
        while (c.moveToNext()) {
            final String documentId = c.getString(0);
            final Uri documentUri = DocumentsContract.buildDocumentUriUsingTree(self,
                    documentId);
            results.add(documentUri);
        }
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
    } finally {
        closeQuietly(c);
    }

    return results.toArray(new Uri[results.size()]);
}
 
Example #7
Source File: UploadWidgetActivity.java    From cloudinary_android with MIT License 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == MEDIA_CHOOSER_REQUEST_CODE) {
        if (resultCode == RESULT_OK && data != null) {
            ArrayList<Uri> uris = extractImageUris(data);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
                for (Uri uri : uris) {
                    if (DocumentsContract.isDocumentUri(this, uri)) {
                        getContentResolver().takePersistableUriPermission(uri, takeFlags);
                    }
                }
            }

            showImages(uris);
        } else {
            setResult(RESULT_CANCELED);
            finish();
        }
    }
}
 
Example #8
Source File: OFileManager.java    From hr with GNU Affero General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
public String getDocPath(Uri uri) {
    String wholeID = DocumentsContract.getDocumentId(uri);
    String id = wholeID.split(":")[1];
    String[] column = {MediaStore.Images.Media.DATA};
    String sel = MediaStore.Images.Media._ID + "=?";
    Cursor cursor = mActivity.getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column, sel,
            new String[]{id}, null);
    String filePath = null;
    int columnIndex = cursor.getColumnIndex(column[0]);
    if (cursor.moveToFirst()) {
        filePath = cursor.getString(columnIndex);
    }
    cursor.close();
    return filePath;
}
 
Example #9
Source File: StorageProviderFragment.java    From storage-samples with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.sample_action) {
        toggleLogin();
        item.setTitle(mLoggedIn ? R.string.log_out : R.string.log_in);

        // BEGIN_INCLUDE(notify_change)
        // Notify the system that the status of our roots has changed.  This will trigger
        // a call to MyCloudProvider.queryRoots() and force a refresh of the system
        // picker UI.  It's important to call this or stale results may persist.
        getActivity().getContentResolver().notifyChange(DocumentsContract.buildRootsUri
                (AUTHORITY), null, false);
        // END_INCLUDE(notify_change)
    }
    return true;
}
 
Example #10
Source File: UriUtils.java    From YZxing with Apache License 2.0 6 votes vote down vote up
private static String getPicturePathFromUriAboveApi19(Context context, Uri uri) {
    String filePath = null;
    if (DocumentsContract.isDocumentUri(context, uri)) {
        // 如果是document类型的 uri, 则通过document id来进行处理
        String documentId = DocumentsContract.getDocumentId(uri);
        if (isMediaDocument(uri)) { // MediaProvider
            // 使用':'分割
            String id = documentId.split(":")[1];

            String selection = MediaStore.Images.Media._ID + "=?";
            String[] selectionArgs = {id};
            filePath = getDataColumn(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection, selectionArgs);
        } else if (isDownloadsDocument(uri)) { // DownloadsProvider
            Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(documentId));
            filePath = getDataColumn(context, contentUri, null, null);
        }
    } else if ("content".equalsIgnoreCase(uri.getScheme())) {
        // 如果是 content 类型的 Uri
        filePath = getDataColumn(context, uri, null, null);
    } else if ("file".equals(uri.getScheme())) {
        // 如果是 file 类型的 Uri,直接获取图片对应的路径
        filePath = uri.getPath();
    }
    return filePath;
}
 
Example #11
Source File: AdapterDocuments.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void createFolder(String new_name)
{
    try
    {
        Uri new_uri = DocumentsContract.createDocument(ctx.getContentResolver(), uri, Document.MIME_TYPE_DIR,
                new_name);
        if (new_uri != null)
        {
            notifyRefr(new_name);
            return;
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    notify(ctx.getString(R.string.fman_create_folder_error, new_name), CommanderIf.OPERATION_FAILED);
}
 
Example #12
Source File: FileUtil.java    From Hentoid with Apache License 2.0 6 votes vote down vote up
private static boolean isDocumentsProviderCached(Context context, String authority) {
    if (providersCache.containsKey(authority)) {
        Boolean b = providersCache.get(authority);
        if (b != null) return b;
    }
    final Intent intent = new Intent(DocumentsContract.PROVIDER_INTERFACE);
    final List<ResolveInfo> infos = context.getPackageManager()
            .queryIntentContentProviders(intent, 0);
    for (ResolveInfo info : infos) {
        if (authority.equals(info.providerInfo.authority)) {
            providersCache.put(authority, true);
            return true;
        }
    }
    providersCache.put(authority, false);
    return false;
}
 
Example #13
Source File: DocumentsContractApi21.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public static Uri createFile(Context context, Uri self, String mimeType,
        String displayName) {
    try {
        return DocumentsContract.createDocument(context.getContentResolver(), self, mimeType,
                displayName);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #14
Source File: DocumentsContractApi21.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
public static Uri[] listFiles(Context context, Uri self) {
    final ContentResolver resolver = context.getContentResolver();
    final Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(self,
            DocumentsContract.getDocumentId(self));
    final ArrayList<Uri> results = new ArrayList<Uri>();

    Cursor c = null;
    try {
        c = resolver.query(childrenUri, new String[] {
                DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null);
        while (c.moveToNext()) {
            final String documentId = c.getString(0);
            final Uri documentUri = DocumentsContract.buildDocumentUriUsingTree(self,
                    documentId);
            results.add(documentUri);
        }
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
    } finally {
        closeQuietly(c);
    }

    return results.toArray(new Uri[results.size()]);
}
 
Example #15
Source File: CrossProfileDocumentsProvider.java    From Shelter with Do What The F*ck You Want To Public License 6 votes vote down vote up
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) {
    ensureServiceBound();
    List<Map<String, Serializable>> files;
    try {
        files = mService.loadFiles(parentDocumentId);
    } catch (RemoteException e) {
        return null;
    }
    final MatrixCursor result = new MatrixCursor(projection == null ? DEFAULT_DOCUMENT_PROJECTION : projection);
    // Allow receiving notification on create / delete
    result.setNotificationUri(getContext().getContentResolver(),
            DocumentsContract.buildDocumentUri(AUTHORITY, parentDocumentId));

    for (Map<String, Serializable> file : files) {
        includeFile(result, file);
    }
    return result;
}
 
Example #16
Source File: DocumentsContractApi21.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public static Uri[] listFiles(Context context, Uri self) {
    final ContentResolver resolver = context.getContentResolver();
    final Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(self,
            DocumentsContract.getDocumentId(self));
    final ArrayList<Uri> results = new ArrayList<Uri>();

    Cursor c = null;
    try {
        c = resolver.query(childrenUri, new String[] {
                DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null);
        while (c.moveToNext()) {
            final String documentId = c.getString(0);
            final Uri documentUri = DocumentsContract.buildDocumentUriUsingTree(self,
                    documentId);
            results.add(documentUri);
        }
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
    } finally {
        closeQuietly(c);
    }

    return results.toArray(new Uri[results.size()]);
}
 
Example #17
Source File: DocumentTreeFS.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean exists() throws IOException
{
    Cursor c = null;
    try
    {
        c = _context.getContentResolver().query(_documentUri, new String[]{
                DocumentsContract.Document.COLUMN_DOCUMENT_ID}, null, null, null);
        return c != null && c.getCount() > 0;
    }
    catch (Exception e)
    {
        if(GlobalConfig.isDebug())
            Logger.log(e);
    }
    finally
    {
        closeQuietly(c);
    }
    return false;
}
 
Example #18
Source File: IOUtils.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Uri findChildDocument(ContentResolver contentResolver, Uri uri, String displayName) {
	String[] projection = {DocumentsContract.Document.COLUMN_DOCUMENT_ID,
			DocumentsContract.Document.COLUMN_DISPLAY_NAME};
	Uri childUri = DocumentsContract.buildChildDocumentsUriUsingTree(uri,
			DocumentsContract.getDocumentId(uri));
	Cursor cursor = contentResolver.query(childUri, projection, null, null, null);
	try {
		while (cursor.moveToNext()) {
			if (displayName.equals(cursor.getString(1))) {
				return DocumentsContract.buildDocumentUriUsingTree(uri, cursor.getString(0));
			}
		}
	} finally {
		cursor.close();
	}
	return null;
}
 
Example #19
Source File: FSCursorBase.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
private Object getDocumentValue(CachedPathInfo cpi, String columnName)
{
    switch (columnName)
    {
        case DocumentsContract.Document.COLUMN_DISPLAY_NAME:
            return cpi.getName();
        case DocumentsContract.Document.COLUMN_DOCUMENT_ID:
            Location tmp = _location.copy();
            tmp.setCurrentPath(cpi.getPath());
            return getDocumentIdFromLocation(tmp);
        case DocumentsContract.Document.COLUMN_FLAGS:
            return getDocumentFlags(cpi);
        //icon is null
        //case DocumentsContract.Document.COLUMN_ICON:
        case DocumentsContract.Document.COLUMN_LAST_MODIFIED:
            return cpi.getModificationDate().getTime();
        case DocumentsContract.Document.COLUMN_MIME_TYPE:
            return getDocumentMimeType(cpi);
        case DocumentsContract.Document.COLUMN_SIZE:
            return cpi.getSize();
        //summary is null
        //case DocumentsContract.Document.COLUMN_SUMMARY:
    }
    return null;
}
 
Example #20
Source File: ContainersDocumentProviderBase.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDocumentType(String documentId) throws FileNotFoundException
{
    try
    {
        Location loc = getLocationsManager().getLocation(getLocationUriFromDocumentId(documentId));
        return LoadPathInfoObservable.create(loc).map(cpi -> cpi.isFile() ?
                FileOpsService.getMimeTypeFromExtension(
                        getContext(),
                        new StringPathUtil(cpi.getName()).getFileExtension()
                ) : DocumentsContract.Document.MIME_TYPE_DIR
        ).
                subscribeOn(Schedulers.io()).
                blockingGet();
    }
    catch (Exception e)
    {
        Logger.log(e);
        throw new IllegalArgumentException("Wrong document uri", e);
    }
}
 
Example #21
Source File: DocumentsContractApi19.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static boolean isFile(Context context, Uri self) {
    final String type = getRawType(context, self);
    if (DocumentsContract.Document.MIME_TYPE_DIR.equals(type) || TextUtils.isEmpty(type)) {
        return false;
    } else {
        return true;
    }
}
 
Example #22
Source File: TreeUriUtils.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String getVolumeIdFromTreeUri(final Uri treeUri) {
    final String docId = DocumentsContract.getTreeDocumentId(treeUri);
    final String[] split = docId.split(":");
    if (split.length > 0) return split[0];
    else return null;
}
 
Example #23
Source File: DocumentsContractApi19.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static boolean exists(Context context, Uri self) {
    final ContentResolver resolver = context.getContentResolver();

    Cursor c = null;
    try {
        c = resolver.query(self, new String[] {
                DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null);
        return c.getCount() > 0;
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
        return false;
    } finally {
        closeQuietly(c);
    }
}
 
Example #24
Source File: MountServerActivity.java    From samba-documents-provider with GNU General Public License v3.0 5 votes vote down vote up
private void launchFileManager(DocumentMetadata metadata) {
  final Uri rootUri = DocumentsContract.buildRootUri(
      SambaDocumentsProvider.AUTHORITY, toRootId(metadata));

  if (launchFileManager(Intent.ACTION_VIEW, rootUri)) {
    return;
  }

  if (launchFileManager(ACTION_BROWSE, rootUri)) {
    return;
  }

  Log.w(TAG, "Failed to find an activity to show mounted root.");
}
 
Example #25
Source File: DocumentTreeFS.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
public void setLastModified(Date dt) throws IOException
{
    final ContentResolver resolver = _context.getContentResolver();
    ContentValues cv = new ContentValues();
    cv.put(DocumentsContract.Document.COLUMN_LAST_MODIFIED, dt.getTime());
    try
    {
        if (resolver.update(getDocumentUri(), cv, null, null) == 0)
            throw new IOException("Failed setting last modified time");
    }
    catch (UnsupportedOperationException e)
    {
        throw new IOException("Failed setting last modified time", e);
    }
}
 
Example #26
Source File: DocumentTreeFS.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
@Override
public com.sovworks.eds.fs.File createFile(String name) throws IOException
{
    String mimeType = FileOpsService.getMimeTypeFromExtension(_context, new StringPathUtil(name).getFileExtension());
    Uri uri = DocumentsContract.createDocument(
            _context.getContentResolver(),
            _path.getDocumentUri(),
            mimeType, name);
    if(uri == null)
        throw new IOException("Failed creating file");
    return new File(new DocumentPath(uri));
}
 
Example #27
Source File: DocumentTreeFS.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
@Override
public com.sovworks.eds.fs.Directory createDirectory(String name) throws IOException
{
    Uri uri = DocumentsContract.createDocument(
            _context.getContentResolver(),
            _path.getDocumentUri(),
            DocumentsContract.Document.MIME_TYPE_DIR,
            name
    );
    if(uri == null)
        throw new IOException("Failed creating folder");
    return new Directory(new DocumentPath(uri));
}
 
Example #28
Source File: DocumentTreeFS.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
public DocumentTreeFS(Context context, Uri rootUri)
{
    _context = context;
    _rootPath = new DocumentPath(
            DocumentsContract.buildDocumentUriUsingTree(
                    rootUri,
                    DocumentsContract.getTreeDocumentId(rootUri)
            )
    );
}
 
Example #29
Source File: FileHelper.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
public static String getRealPathFromURI_API19(Context context, Uri uri) {
    String filePath = "";
    try {
        String wholeID = DocumentsContract.getDocumentId(uri);

        // Split at colon, use second item in the array
        String id = wholeID.indexOf(":") > -1 ? wholeID.split(":")[1] : wholeID.indexOf(";") > -1 ? wholeID
                .split(";")[1] : wholeID;

        String[] column = { MediaStore.Images.Media.DATA };

        // where id is equal to
        String sel = MediaStore.Images.Media._ID + "=?";

        Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column,
                sel, new String[] { id }, null);

        int columnIndex = cursor.getColumnIndex(column[0]);

        if (cursor.moveToFirst()) {
            filePath = cursor.getString(columnIndex);
        }
        cursor.close();
    } catch (Exception e) {
        filePath = "";
    }
    return filePath;
}
 
Example #30
Source File: DocumentsContractApi19.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public static boolean canWrite(Context context, Uri self) {
    // Ignore if grant doesn't allow write
    if (context.checkCallingOrSelfUriPermission(self, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
            != PackageManager.PERMISSION_GRANTED) {
        return false;
    }

    final String type = getRawType(context, self);
    final int flags = queryForInt(context, self, DocumentsContract.Document.COLUMN_FLAGS, 0);

    // Ignore documents without MIME
    if (TextUtils.isEmpty(type)) {
        return false;
    }

    // Deletable documents considered writable
    if ((flags & DocumentsContract.Document.FLAG_SUPPORTS_DELETE) != 0) {
        return true;
    }

    if (DocumentsContract.Document.MIME_TYPE_DIR.equals(type)
            && (flags & DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE) != 0) {
        // Directories that allow create considered writable
        return true;
    } else if (!TextUtils.isEmpty(type)
            && (flags & DocumentsContract.Document.FLAG_SUPPORTS_WRITE) != 0) {
        // Writable normal files considered writable
        return true;
    }

    return false;
}