android.provider.DocumentsContract.Root Java Examples

The following examples show how to use android.provider.DocumentsContract.Root. 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: DocumentsProvider.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation is provided by the parent class. Cannot be overridden.
 *
 * @see #getDocumentType(String)
 */
@Override
public final String getType(Uri uri) {
    try {
        switch (mMatcher.match(uri)) {
            case MATCH_ROOT:
                return DocumentsContract.Root.MIME_TYPE_ITEM;
            case MATCH_DOCUMENT:
            case MATCH_DOCUMENT_TREE:
                enforceTree(uri);
                return getDocumentType(getDocumentId(uri));
            default:
                return null;
        }
    } catch (FileNotFoundException e) {
        Log.w(TAG, "Failed during getType", e);
        return null;
    }
}
 
Example #2
Source File: LocalStorageProvider.java    From droidddle with Apache License 2.0 6 votes vote down vote up
@Override
public Cursor queryRoots(final String[] projection) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.internal_storage));
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_ICON, R.drawable.ic_shot_project);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (roots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
 
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 Cursor queryRoots(final String[] projection) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection
            : DEFAULT_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_TITLE, "internal storage");
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    //row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (roots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
 
Example #4
Source File: LocalStorageProvider.java    From qiniu-lab-android with MIT License 6 votes vote down vote up
@Override
public Cursor queryRoots(final String[] projection) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection
            : DEFAULT_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.internal_storage));
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (roots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
 
Example #5
Source File: LocalStorageProvider.java    From droid-stealth with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Cursor queryRoots(final String[] projection) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection
            : DEFAULT_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.internal_storage));
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (roots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
 
Example #6
Source File: LocalStorageProvider.java    From Effects-Pro with MIT License 6 votes vote down vote up
@Override
public Cursor queryRoots(final String[] projection) throws FileNotFoundException {
	// Create a cursor with either the requested fields, or the default
	// projection if "projection" is null.
	final MatrixCursor result = new MatrixCursor(projection != null ? projection
			: DEFAULT_ROOT_PROJECTION);
	// Add Home directory
	File homeDir = Environment.getExternalStorageDirectory();
	final MatrixCursor.RowBuilder row = result.newRow();
	// These columns are required
	row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
	row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
	row.add(Root.COLUMN_TITLE, getContext().getString(R.string.internal_storage));
	row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
	row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
	// These columns are optional
	row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
	// Root.COLUMN_MIME_TYPE is another optional column and useful if you
	// have multiple roots with different
	// types of mime types (roots that don't match the requested mime type
	// are automatically hidden)
	return result;
}
 
Example #7
Source File: LocalStorageProvider.java    From filechooser with MIT License 6 votes vote down vote up
@Override
public Cursor queryRoots(final String[] projection) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection
            : DEFAULT_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.internal_storage));
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (roots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
 
Example #8
Source File: LocalStorageProvider.java    From secrecy with Apache License 2.0 6 votes vote down vote up
@Override
public Cursor queryRoots(final String[] projection) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection
            : DEFAULT_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.internal_storage));
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (roots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
 
Example #9
Source File: LocalStorageProvider.java    From Readily with MIT License 6 votes vote down vote up
@Override
public Cursor queryRoots(final String[] projection) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection
            : DEFAULT_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getParent());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getParent());
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.all_storage));
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (ro`ots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
 
Example #10
Source File: AppStorageProvider.java    From JPPF with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor queryRoots(final String[] projection) throws FileNotFoundException {
  Log.d(LOG_TAG, "queryRoots() root dir = " + rootDir);
  String[] resolvedProjection = resolveProjection(projection, DEFAULT_ROOT_PROJECTION);
  MatrixCursor result = new MatrixCursor(resolvedProjection);
  MatrixCursor.RowBuilder row = result.newRow();
  row.add(Root.COLUMN_ROOT_ID, ROOT_ID);
  row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE /*| Root.FLAG_SUPPORTS_RECENTS*/ | Root.FLAG_SUPPORTS_SEARCH);
  row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_name));
  row.add(Root.COLUMN_DOCUMENT_ID, ROOT_ID);
  row.add(Root.COLUMN_AVAILABLE_BYTES, rootDir.getFreeSpace());
  row.add(Root.COLUMN_ICON, R.mipmap.jppf_icon);
  return result;
}
 
Example #11
Source File: SambaDocumentsProvider.java    From samba-documents-provider with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
  if(BuildConfig.DEBUG) Log.d(TAG, "Querying roots.");
  projection = (projection == null) ? DEFAULT_ROOT_PROJECTION : projection;

  MatrixCursor cursor = new MatrixCursor(projection);

  for (String uri : mShareManager) {
    if (!mShareManager.isShareMounted(uri)) {
      continue;
    }

    final String name;
    final Uri parsedUri = Uri.parse(uri);
    try(CacheResult result = mCache.get(parsedUri)) {
      final DocumentMetadata metadata;
      if (result.getState() == CacheResult.CACHE_MISS) {
        metadata = DocumentMetadata.createShare(parsedUri);
        mCache.put(metadata);
      } else {
        metadata = result.getItem();
      }

      name = metadata.getDisplayName();

      cursor.addRow(new Object[] {
          toRootId(metadata),
          toDocumentId(parsedUri),
          name,
          Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_EJECT,
          R.drawable.ic_folder_shared
      });
    }

  }
  return cursor;
}
 
Example #12
Source File: ScienceJournalDocsProvider.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
  // Use a MatrixCursor to build a cursor
  // with either the requested fields, or the default
  // projection if "projection" is null.
  final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));

  final MatrixCursor.RowBuilder row = result.newRow();
  row.add(Root.COLUMN_ROOT_ID, DEFAULT_ROOT_PROJECTION);

  // TODO: Implement Root.FLAG_SUPPORTS_RECENTS and Root.FLAG_SUPPORTS_SEARCH.
  // This will mean documents will show up in the "recents" category and be searchable.

  // COLUMN_TITLE is the root title (e.g. Gallery, Drive).
  row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_name));

  // This document id cannot change after it's shared.
  row.add(Root.COLUMN_DOCUMENT_ID, ROOT_DIRECTORY_ID);

  // The child MIME types are used to filter the roots and only present to the
  // user those roots that contain the desired type somewhere in their file hierarchy.
  row.add(Root.COLUMN_MIME_TYPES, "image/*");

  row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);

  return result;
}
 
Example #13
Source File: MyCloudProvider.java    From storage-samples with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    Log.v(TAG, "queryRoots");

    // Create a cursor with either the requested fields, or the default projection.  This
    // cursor is returned to the Android system picker UI and used to display all roots from
    // this provider.
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));

    // If user is not logged in, return an empty root cursor.  This removes our provider from
    // the list entirely.
    if (!isUserLoggedIn()) {
        return result;
    }

    // It's possible to have multiple roots (e.g. for multiple accounts in the same app) -
    // just add multiple cursor rows.
    // Construct one row for a root called "MyCloud".
    final MatrixCursor.RowBuilder row = result.newRow();

    row.add(Root.COLUMN_ROOT_ID, ROOT);
    row.add(Root.COLUMN_SUMMARY, getContext().getString(R.string.root_summary));

    // FLAG_SUPPORTS_CREATE means at least one directory under the root supports creating
    // documents.  FLAG_SUPPORTS_RECENTS means your application's most recently used
    // documents will show up in the "Recents" category.  FLAG_SUPPORTS_SEARCH allows users
    // to search all documents the application shares.
    row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE |
            Root.FLAG_SUPPORTS_RECENTS |
            Root.FLAG_SUPPORTS_SEARCH);

    // COLUMN_TITLE is the root title (e.g. what will be displayed to identify your provider).
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_name));

    // This document id must be unique within this provider and consistent across time.  The
    // system picker UI may save it and refer to it later.
    row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(mBaseDir));

    // The child MIME types are used to filter the roots and only present to the user roots
    // that contain the desired type somewhere in their file hierarchy.
    row.add(Root.COLUMN_MIME_TYPES, getChildMimeTypes(mBaseDir));
    row.add(Root.COLUMN_AVAILABLE_BYTES, mBaseDir.getFreeSpace());
    row.add(Root.COLUMN_ICON, R.drawable.ic_launcher);

    return result;
}
 
Example #14
Source File: MyCloudProvider.java    From android-StorageProvider with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    Log.v(TAG, "queryRoots");

    // Create a cursor with either the requested fields, or the default projection.  This
    // cursor is returned to the Android system picker UI and used to display all roots from
    // this provider.
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));

    // If user is not logged in, return an empty root cursor.  This removes our provider from
    // the list entirely.
    if (!isUserLoggedIn()) {
        return result;
    }

    // It's possible to have multiple roots (e.g. for multiple accounts in the same app) -
    // just add multiple cursor rows.
    // Construct one row for a root called "MyCloud".
    final MatrixCursor.RowBuilder row = result.newRow();

    row.add(Root.COLUMN_ROOT_ID, ROOT);
    row.add(Root.COLUMN_SUMMARY, getContext().getString(R.string.root_summary));

    // FLAG_SUPPORTS_CREATE means at least one directory under the root supports creating
    // documents.  FLAG_SUPPORTS_RECENTS means your application's most recently used
    // documents will show up in the "Recents" category.  FLAG_SUPPORTS_SEARCH allows users
    // to search all documents the application shares.
    row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE |
            Root.FLAG_SUPPORTS_RECENTS |
            Root.FLAG_SUPPORTS_SEARCH);

    // COLUMN_TITLE is the root title (e.g. what will be displayed to identify your provider).
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_name));

    // This document id must be unique within this provider and consistent across time.  The
    // system picker UI may save it and refer to it later.
    row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(mBaseDir));

    // The child MIME types are used to filter the roots and only present to the user roots
    // that contain the desired type somewhere in their file hierarchy.
    row.add(Root.COLUMN_MIME_TYPES, getChildMimeTypes(mBaseDir));
    row.add(Root.COLUMN_AVAILABLE_BYTES, mBaseDir.getFreeSpace());
    row.add(Root.COLUMN_ICON, R.drawable.ic_launcher);

    return result;
}