android.provider.MediaStore.Files.FileColumns Java Examples

The following examples show how to use android.provider.MediaStore.Files.FileColumns. 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: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private boolean isEmpty(Uri uri, String type) {
    final ContentResolver resolver = getContext().getContentResolver();
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        String[] mimeType;
        if (TYPE_DOCUMENT_ROOT.equals(type)) {
            mimeType = DOCUMENT_MIMES;
        } else if (TYPE_ARCHIVE_ROOT.equals(type)) {
            mimeType = ARCHIVE_MIMES;
        } else if (TYPE_APK_ROOT.equals(type)) {
            mimeType = APK_MIMES;
        } else {
            return true;
        }
        cursor = resolver.query(FILE_URI,
                FileQuery.PROJECTION,
                FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")" , null, null);
        return (cursor == null) || (cursor.getCount() == 0);
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
}
 
Example #2
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private boolean isEmpty(Uri uri, String type) {
    final ContentResolver resolver = getContext().getContentResolver();
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        String[] mimeType;
        if (TYPE_DOCUMENT_ROOT.equals(type)) {
            mimeType = DOCUMENT_MIMES;
        } else if (TYPE_ARCHIVE_ROOT.equals(type)) {
            mimeType = ARCHIVE_MIMES;
        } else if (TYPE_APK_ROOT.equals(type)) {
            mimeType = APK_MIMES;
        } else {
            return true;
        }
        cursor = resolver.query(FILE_URI,
                FileQuery.PROJECTION,
                FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")" , null, null);
        return (cursor == null) || (cursor.getCount() == 0);
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
}
 
Example #3
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private boolean isEmpty(Uri uri, String type) {
    final ContentResolver resolver = getContext().getContentResolver();
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        String[] mimeType;
        if (TYPE_DOCUMENT_ROOT.equals(type)) {
            mimeType = DOCUMENT_MIMES;
        } else if (TYPE_ARCHIVE_ROOT.equals(type)) {
            mimeType = ARCHIVE_MIMES;
        } else if (TYPE_APK_ROOT.equals(type)) {
            mimeType = APK_MIMES;
        } else {
            return true;
        }
        cursor = resolver.query(FILE_URI,
                FileQuery.PROJECTION,
                FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")" , null, null);
        return (cursor == null) || (cursor.getCount() == 0);
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
}
 
Example #4
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void queryFile(ContentResolver resolver, Cursor cursor, MatrixCursor result, String[] mimeType, String like) {
    // single file
    cursor = resolver.query(FILE_URI,
            FileQuery.PROJECTION,
            FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")"
            + " OR " + FileColumns.MIME_TYPE + " LIKE "+ "'"+like+"%'",
            null,
            null);
    copyNotificationUri(result, FILE_URI);
    while (cursor.moveToNext()) {
        includeFile(result, cursor);
    }
}
 
Example #5
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void queryRecentFile(ContentResolver resolver, Cursor cursor, MatrixCursor result, String[] mimeType) {
    // single file
    cursor = resolver.query(FILE_URI,
            FileQuery.PROJECTION, FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")" , null,
            FileQuery.DATE_MODIFIED + " DESC");
    copyNotificationUri(result, FILE_URI);
    while (cursor.moveToNext() && result.getCount() < 64) {
        includeFile(result, cursor);
    }
}
 
Example #6
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void queryFile(ContentResolver resolver, Cursor cursor, MatrixCursor result, String[] mimeType) {
    // single file
    cursor = resolver.query(FILE_URI,
            FileQuery.PROJECTION, FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")" , null,
            null);
    copyNotificationUri(result, FILE_URI);
    while (cursor.moveToNext()) {
        includeFile(result, cursor);
    }
}
 
Example #7
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void queryFile(ContentResolver resolver, Cursor cursor, MatrixCursor result, String[] mimeType, String like) {
    // single file
    cursor = resolver.query(FILE_URI,
            FileQuery.PROJECTION,
            FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")"
            + " OR " + FileColumns.MIME_TYPE + " LIKE "+ "'"+like+"%'",
            null,
            null);
    copyNotificationUri(result, FILE_URI);
    while (cursor.moveToNext()) {
        includeFile(result, cursor);
    }
}
 
Example #8
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
/**
 * When inserting the first item of each type, we need to trigger a roots
 * refresh to clear a previously reported {@link Root#FLAG_EMPTY}.
 */
static void onMediaStoreInsert(Context context, String volumeName, int type, long id) {
    if (!"external".equals(volumeName)) return;

    if (type == FileColumns.MEDIA_TYPE_IMAGE && sReturnedImagesEmpty) {
        sReturnedImagesEmpty = false;
        notifyRootsChanged(context);
    } else if (type == FileColumns.MEDIA_TYPE_VIDEO && sReturnedVideosEmpty) {
        sReturnedVideosEmpty = false;
        notifyRootsChanged(context);
    } else if (type == FileColumns.MEDIA_TYPE_AUDIO && sReturnedAudioEmpty) {
        sReturnedAudioEmpty = false;
        notifyRootsChanged(context);
    }
}
 
Example #9
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void queryRecentFile(ContentResolver resolver, Cursor cursor, MatrixCursor result, String[] mimeType) {
    // single file
    cursor = resolver.query(FILE_URI,
            FileQuery.PROJECTION, FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")" , null,
            FileQuery.DATE_MODIFIED + " DESC");
    copyNotificationUri(result, FILE_URI);
    while (cursor.moveToNext() && result.getCount() < 64) {
        includeFile(result, cursor);
    }
}
 
Example #10
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void queryFile(ContentResolver resolver, Cursor cursor, MatrixCursor result, String[] mimeType) {
    // single file
    cursor = resolver.query(FILE_URI,
            FileQuery.PROJECTION, FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")" , null,
            null);
    copyNotificationUri(result, FILE_URI);
    while (cursor.moveToNext()) {
        includeFile(result, cursor);
    }
}
 
Example #11
Source File: BucketHelper.java    From medialibrary with Apache License 2.0 5 votes vote down vote up
private static BucketEntry[] loadBucketEntriesFromFilesTable(
        ThreadPool.JobContext jc, ContentResolver resolver, int type) {
    Uri uri = getFilesContentUri();
    Cursor cursor = resolver.query(uri,
            PROJECTION_BUCKET, BUCKET_GROUP_BY,
            null, BUCKET_ORDER_BY);
    if (cursor == null) {
        Log.w(TAG, "cannot open local database: " + uri);
        return new BucketEntry[0];
    }
    ArrayList<BucketEntry> buffer = new ArrayList<BucketEntry>();
    int typeBits = 0;
    if ((type & MediaObject.MEDIA_TYPE_IMAGE) != 0) {
        typeBits |= (1 << FileColumns.MEDIA_TYPE_IMAGE);
    }
    if ((type & MediaObject.MEDIA_TYPE_VIDEO) != 0) {
        typeBits |= (1 << FileColumns.MEDIA_TYPE_VIDEO);
    }
    try {
        while (cursor.moveToNext()) {
            if ((typeBits & (1 << cursor.getInt(INDEX_MEDIA_TYPE))) != 0) {
                BucketEntry entry = new BucketEntry(
                        cursor.getInt(INDEX_BUCKET_ID),
                        cursor.getString(INDEX_BUCKET_NAME));
                if (!buffer.contains(entry)) {
                    buffer.add(entry);
                }
            }
            if (jc.isCancelled()) return null;
        }
    } finally {
        Utils.closeSilently(cursor);
    }
    return buffer.toArray(new BucketEntry[buffer.size()]);
}
 
Example #12
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
/**
 * When inserting the first item of each type, we need to trigger a roots
 * refresh to clear a previously reported {@link Root#FLAG_EMPTY}.
 */
static void onMediaStoreInsert(Context context, String volumeName, int type, long id) {
    if (!"external".equals(volumeName)) return;

    if (type == FileColumns.MEDIA_TYPE_IMAGE && sReturnedImagesEmpty) {
        sReturnedImagesEmpty = false;
        notifyRootsChanged(context);
    } else if (type == FileColumns.MEDIA_TYPE_VIDEO && sReturnedVideosEmpty) {
        sReturnedVideosEmpty = false;
        notifyRootsChanged(context);
    } else if (type == FileColumns.MEDIA_TYPE_AUDIO && sReturnedAudioEmpty) {
        sReturnedAudioEmpty = false;
        notifyRootsChanged(context);
    }
}
 
Example #13
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void queryRecentFile(ContentResolver resolver, Cursor cursor, MatrixCursor result, String[] mimeType) {
    // single file
    cursor = resolver.query(FILE_URI,
            FileQuery.PROJECTION, FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")" , null,
            FileQuery.DATE_MODIFIED + " DESC");
    copyNotificationUri(result, FILE_URI);
    while (cursor.moveToNext() && result.getCount() < 64) {
        includeFile(result, cursor);
    }
}
 
Example #14
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void queryFile(ContentResolver resolver, Cursor cursor, MatrixCursor result, String[] mimeType) {
    // single file
    cursor = resolver.query(FILE_URI,
            FileQuery.PROJECTION, FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")" , null,
            null);
    copyNotificationUri(result, FILE_URI);
    while (cursor.moveToNext()) {
        includeFile(result, cursor);
    }
}
 
Example #15
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void queryFile(ContentResolver resolver, Cursor cursor, MatrixCursor result, String[] mimeType, String like) {
    // single file
    cursor = resolver.query(FILE_URI,
            FileQuery.PROJECTION,
            FileColumns.MIME_TYPE + " IN "+ "("+toString(mimeType)+")"
            + " OR " + FileColumns.MIME_TYPE + " LIKE "+ "'"+like+"%'",
            null,
            null);
    copyNotificationUri(result, FILE_URI);
    while (cursor.moveToNext()) {
        includeFile(result, cursor);
    }
}
 
Example #16
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
/**
 * When inserting the first item of each type, we need to trigger a roots
 * refresh to clear a previously reported {@link Root#FLAG_EMPTY}.
 */
static void onMediaStoreInsert(Context context, String volumeName, int type, long id) {
    if (!"external".equals(volumeName)) return;

    if (type == FileColumns.MEDIA_TYPE_IMAGE && sReturnedImagesEmpty) {
        sReturnedImagesEmpty = false;
        notifyRootsChanged(context);
    } else if (type == FileColumns.MEDIA_TYPE_VIDEO && sReturnedVideosEmpty) {
        sReturnedVideosEmpty = false;
        notifyRootsChanged(context);
    } else if (type == FileColumns.MEDIA_TYPE_AUDIO && sReturnedAudioEmpty) {
        sReturnedAudioEmpty = false;
        notifyRootsChanged(context);
    }
}
 
Example #17
Source File: BucketHelper.java    From medialibrary with Apache License 2.0 5 votes vote down vote up
public static  BucketEntry[] loadBucketEntries(Path path, ThreadPool.JobContext jc, Context mContext) {
    Uri uri = mBaseUri;
    Log.v("DebugLoadingTime", "start quering media provider");
    Cursor cursor = mContext.getContentResolver().query(
            uri, PROJECTION_BUCKET, BUCKET_GROUP_BY, null, BUCKET_ORDER_BY);
    if (cursor == null) {
        Log.w(TAG, "cannot open local database: " + uri);
        return new BucketEntry[0];
    }
    ArrayList<BucketEntry> buffer = new ArrayList<BucketEntry>();
    int typeBits = 0;
    int mType = getTypeFromPath(path);
    if ((mType & MediaObject.MEDIA_TYPE_IMAGE) != 0) {
        typeBits |= (1 << FileColumns.MEDIA_TYPE_IMAGE);
    }
    if ((mType & MediaObject.MEDIA_TYPE_VIDEO) != 0) {
        typeBits |= (1 << FileColumns.MEDIA_TYPE_VIDEO);
    }
    try {
        while (cursor.moveToNext()) {
            if ((typeBits & (1 << cursor.getInt(INDEX_MEDIA_TYPE))) != 0) {
                BucketEntry entry = new BucketEntry(
                        cursor.getInt(INDEX_BUCKET_ID),
                        cursor.getString(INDEX_BUCKET_NAME));
                if (!buffer.contains(entry)) {
                    buffer.add(entry);
                }
            }
            if (jc.isCancelled()) return null;
        }
        Log.v("DebugLoadingTime", "got " + buffer.size() + " buckets");
    } finally {
        cursor.close();
    }
    return buffer.toArray(new BucketEntry[buffer.size()]);
}