android.provider.MediaStore.Images.ImageColumns Java Examples

The following examples show how to use android.provider.MediaStore.Images.ImageColumns. 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: IOUtils.java    From MultiView with Apache License 2.0 7 votes vote down vote up
/**
 * Try to return the absolute file path from the given Uri
 * 
 * @param context
 * @param uri
 * @return the file path or null
 */
public static String getRealFilePath( final Context context, final Uri uri ) {

	if ( null == uri ) return null;

	final String scheme = uri.getScheme();
	String data = null;

	if ( scheme == null )
		data = uri.getPath();
	else if ( ContentResolver.SCHEME_FILE.equals( scheme ) ) {
		data = uri.getPath();
	} else if ( ContentResolver.SCHEME_CONTENT.equals( scheme ) ) {
		Cursor cursor = context.getContentResolver().query( uri, new String[] { ImageColumns.DATA }, null, null, null );
		if ( null != cursor ) {
			if ( cursor.moveToFirst() ) {
				int index = cursor.getColumnIndex( ImageColumns.DATA );
				if ( index > -1 ) {
					data = cursor.getString( index );
				}
			}
			cursor.close();
		}
	}
	return data;
}
 
Example #2
Source File: ImageHelper.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
/**
 * Store a picture that has just been saved to disk in the MediaStore.
 * 
 * @param imageFile
 *            The File of the picture
 * @return The Uri provided by the MediaStore.
 */
public static Uri storePicture(final Context ctx, final File imageFile,
        String imageName) {
    final ContentResolver cr = ctx.getContentResolver();
    imageName = imageName.substring(imageName.lastIndexOf('/') + 1);
    final ContentValues values = new ContentValues(7);
    values.put(MediaColumns.TITLE, imageName);
    values.put(MediaColumns.DISPLAY_NAME, imageName);
    values.put(ImageColumns.DESCRIPTION, "");
    values.put(ImageColumns.DATE_TAKEN, System.currentTimeMillis());
    values.put(MediaColumns.MIME_TYPE, "image/jpeg");
    values.put(ImageColumns.ORIENTATION, 0);
    final File parentFile = imageFile.getParentFile();
    final String path = parentFile.toString().toLowerCase();
    final String name = parentFile.getName().toLowerCase();
    values.put(Images.ImageColumns.BUCKET_ID, path.hashCode());
    values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, name);
    values.put("_data", imageFile.toString());

    final Uri uri = cr.insert(Images.Media.EXTERNAL_CONTENT_URI, values);

    return uri;
}
 
Example #3
Source File: MediaStoreCursorHelper.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public static PhotoUpload photosCursorToSelection(Uri contentUri,
		Cursor cursor) {
	PhotoUpload item = null;

	try {
		File file = new File(cursor.getString(cursor
				.getColumnIndexOrThrow(ImageColumns.DATA)));
		if (file.exists()) {
			item = PhotoUpload
					.getSelection(contentUri, cursor.getInt(cursor
							.getColumnIndexOrThrow(ImageColumns._ID)));
		}
	} catch (Exception e) {
		e.printStackTrace();
	}

	return item;
}
 
Example #4
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
protected int queryOrientationForImage(long id, CancellationSignal signal) {
    final ContentResolver resolver = getContext().getContentResolver();

    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                ImageOrientationQuery.PROJECTION, ImageColumns._ID + "=" + id, null, null);
        if (cursor.moveToFirst()) {
            return cursor.getInt(ImageOrientationQuery.ORIENTATION);
        } else {
            Log.w(TAG, "Missing orientation data for " + id);
            return 0;
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
}
 
Example #5
Source File: Utils.java    From android-utils with MIT License 6 votes vote down vote up
@Nullable
/**
 * @deprecated Use {@link MediaUtils#createVideoUri(Context)}
 * Creates external content:// scheme uri to save the videos at.
 */
public static Uri createVideoUri(Context ctx) throws IOException {

    if (ctx == null) {
        throw new NullPointerException("Context cannot be null");
    }

    Uri imageUri;

    ContentValues values = new ContentValues();
    values.put(MediaColumns.TITLE, "");
    values.put(ImageColumns.DESCRIPTION, "");
    imageUri = ctx.getContentResolver().insert(Video.Media.EXTERNAL_CONTENT_URI, values);

    return imageUri;
}
 
Example #6
Source File: Utils.java    From android-utils with MIT License 6 votes vote down vote up
@Nullable
/**
 * @deprecated Use {@link MediaUtils#createImageUri(Context)}
 * Creates external content:// scheme uri to save the images at. The image saved at this
 * {@link android.net.Uri} will be visible via the gallery application on the device.
 */
public static Uri createImageUri(Context ctx) throws IOException {

    if (ctx == null) {
        throw new NullPointerException("Context cannot be null");
    }

    Uri imageUri = null;

    ContentValues values = new ContentValues();
    values.put(MediaColumns.TITLE, "");
    values.put(ImageColumns.DESCRIPTION, "");
    imageUri = ctx.getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);

    return imageUri;
}
 
Example #7
Source File: AlbumController.java    From umeng_community_android with MIT License 6 votes vote down vote up
/**
 * 获取某个相册中的所有图片
 * 
 * @param name
 * @return
 */
public List<PhotoModel> getAlbum(String name) {
    Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] {
            ImageColumns.BUCKET_DISPLAY_NAME,
            ImageColumns.DATA, ImageColumns.DATE_ADDED, ImageColumns.SIZE
    }, "bucket_display_name = ?",
            new String[] {
                name
            }, ImageColumns.DATE_ADDED);
    if (cursor == null || !cursor.moveToNext())
        return new ArrayList<PhotoModel>();
    List<PhotoModel> photos = new ArrayList<PhotoModel>();
    cursor.moveToLast();
    do {
        if (cursor.getLong(cursor.getColumnIndex(ImageColumns.SIZE)) > 1024 * 10) {
            PhotoModel photoModel = new PhotoModel();
            photoModel.setOriginalPath(cursor.getString(cursor
                    .getColumnIndex(ImageColumns.DATA)));
            photos.add(photoModel);
        }
    } while (cursor.moveToPrevious());
    IOUtils.closeQuietly(cursor);
    return photos;
}
 
Example #8
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
protected int queryOrientationForImage(long id, CancellationSignal signal) {
    final ContentResolver resolver = getContext().getContentResolver();

    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                ImageOrientationQuery.PROJECTION, ImageColumns._ID + "=" + id, null, null);
        if (cursor.moveToFirst()) {
            return cursor.getInt(ImageOrientationQuery.ORIENTATION);
        } else {
            Log.w(TAG, "Missing orientation data for " + id);
            return 0;
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
}
 
Example #9
Source File: AlbumController.java    From umeng_community_android with MIT License 6 votes vote down vote up
/**
 * 获取最近使用的照片
 * 
 * @return
 */
public List<PhotoModel> getCurrent() {
    Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] {
            ImageColumns.DATA,
            ImageColumns.DATE_ADDED, ImageColumns.SIZE
    }, null, null, ImageColumns.DATE_ADDED);
    if (cursor == null || !cursor.moveToNext())
        return new ArrayList<PhotoModel>();
    List<PhotoModel> photos = new ArrayList<PhotoModel>();
    cursor.moveToLast();
    do {
        if (cursor.getLong(cursor.getColumnIndex(ImageColumns.SIZE)) > 1024 * 10) {
            PhotoModel photoModel = new PhotoModel();
            photoModel.setOriginalPath(cursor.getString(cursor
                    .getColumnIndex(ImageColumns.DATA)));
            photos.add(photoModel);
        }
    } while (cursor.moveToPrevious());
    IOUtils.closeQuietly(cursor);
    return photos;
}
 
Example #10
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
protected int queryOrientationForImage(long id, CancellationSignal signal) {
    final ContentResolver resolver = getContext().getContentResolver();

    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                ImageOrientationQuery.PROJECTION, ImageColumns._ID + "=" + id, null, null);
        if (cursor.moveToFirst()) {
            return cursor.getInt(ImageOrientationQuery.ORIENTATION);
        } else {
            Log.w(TAG, "Missing orientation data for " + id);
            return 0;
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
}
 
Example #11
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
protected long getImageForBucketCleared(long bucketId) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                ImagesBucketThumbnailQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + bucketId,
                null, ImageColumns.DATE_MODIFIED + " DESC");
        if (cursor.moveToFirst()) {
            return cursor.getLong(ImagesBucketThumbnailQuery._ID);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    throw new FileNotFoundException("No video found for bucket");
}
 
Example #12
Source File: ImageHelper.java    From fanfouapp-opensource with Apache License 2.0 5 votes vote down vote up
public static Uri insertImage(final ContentResolver cr, final File file,
        final int degree) {
    final long size = file.length();
    final String name = file.getName();
    final ContentValues values = new ContentValues(9);
    values.put(MediaColumns.TITLE, name);
    values.put(MediaColumns.DISPLAY_NAME, name);
    values.put(ImageColumns.DATE_TAKEN, System.currentTimeMillis());
    values.put(MediaColumns.MIME_TYPE, "image/jpeg");
    values.put(ImageColumns.ORIENTATION, degree);
    values.put(MediaColumns.DATA, file.getAbsolutePath());
    values.put(MediaColumns.SIZE, size);
    // return cr.insert(STORAGE_URI, values);
    return null;
}
 
Example #13
Source File: MediaStoreCursorHelper.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static void photosCursorToBucketList(Cursor cursor,
		ArrayList<MediaStoreBucket> items) {
	final HashSet<String> bucketIds = new HashSet<String>();

	final int idColumn = cursor.getColumnIndex(ImageColumns.BUCKET_ID);
	final int nameColumn = cursor
			.getColumnIndex(ImageColumns.BUCKET_DISPLAY_NAME);
	final int dataColumn = cursor.getColumnIndex(ImageColumns.SIZE);
	if (cursor.moveToFirst()) {
		do {
			try {
				final String bucketId = cursor.getString(idColumn);
				final long size = cursor.getLong(dataColumn);
				File file = new File(cursor.getString(cursor
						.getColumnIndexOrThrow(ImageColumns.DATA)));
				if (file.exists()) {
					if (bucketIds.add(bucketId)) {
						items.add(new MediaStoreBucket(bucketId, cursor
								.getString(nameColumn)));
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		} while (cursor.moveToNext());
	}
}
 
Example #14
Source File: MainActivity.java    From ImageEditor-android with MIT License 5 votes vote down vote up
/**
 * Pick a random image from the user gallery
 * 
 * @return
 */
@SuppressWarnings("unused")
private Uri pickRandomImage() {
	Cursor c = getContentResolver().query(
			Images.Media.EXTERNAL_CONTENT_URI,
			new String[] { ImageColumns._ID, ImageColumns.DATA },
			ImageColumns.SIZE + ">?", new String[] { "90000" }, null);
	Uri uri = null;

	if (c != null) {
		int total = c.getCount();
		int position = (int) (Math.random() * total);
		Log.d(LOG_TAG, "pickRandomImage. total images: " + total
				+ ", position: " + position);
		if (total > 0) {
			if (c.moveToPosition(position)) {
				String data = c.getString(c
						.getColumnIndex(Images.ImageColumns.DATA));
				long id = c.getLong(c
						.getColumnIndex(Images.ImageColumns._ID));

				uri = Uri.parse(data);

				Log.d(LOG_TAG, uri.toString());
			}
		}
		c.close();
	}
	return uri;
}
 
Example #15
Source File: AlbumController.java    From umeng_community_android with MIT License 5 votes vote down vote up
/**
 * 获取所有相册
 * 
 * @return
 */
public List<AlbumModel> getAlbums() {
    List<AlbumModel> albums = new ArrayList<AlbumModel>();
    Map<String, AlbumModel> map = new HashMap<String, AlbumModel>();
    Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] {
            ImageColumns.DATA,
            ImageColumns.BUCKET_DISPLAY_NAME, ImageColumns.SIZE
    }, null, null, null);
    if (cursor == null || !cursor.moveToNext())
        return new ArrayList<AlbumModel>();
    cursor.moveToLast();
    AlbumModel current = new AlbumModel(ResFinder.getString("umeng_comm_recent_photos"), 0,
            cursor.getString(cursor.getColumnIndex(ImageColumns.DATA)), true); // 最近的照片
    albums.add(current);
    do {
        if (cursor.getInt(cursor.getColumnIndex(ImageColumns.SIZE)) < 1024 * 10) {
            continue;
        }

        current.increaseCount();
        String name = cursor.getString(cursor.getColumnIndex(ImageColumns.BUCKET_DISPLAY_NAME));
        if (map.keySet().contains(name))
            map.get(name).increaseCount();
        else {
            AlbumModel album = new AlbumModel(name, 1, cursor.getString(cursor
                    .getColumnIndex(ImageColumns.DATA)));
            map.put(name, album);
            albums.add(album);
        }
    } while (cursor.moveToPrevious());
    IOUtils.closeQuietly(cursor);
    return albums;
}
 
Example #16
Source File: Image.java    From droidddle with Apache License 2.0 5 votes vote down vote up
protected void setDegreesRotated(int degrees) {
    if (mRotation == degrees)
        return;
    mRotation = degrees;
    ContentValues values = new ContentValues();
    values.put(ImageColumns.ORIENTATION, mRotation);
    mContentResolver.update(mUri, values, null, null);

    //TODO: Consider invalidate the cursor in container
    // ((BaseImageList) getContainer()).invalidateCursor();
}
 
Example #17
Source File: Storage.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
public static ContentValues getContentValuesForData(String title,
                                                    long date, Location location, int orientation, long jpegLength,
                                                    String path, int width, int height, String mimeType)
{

    File file = new File(path);
    long dateModifiedSeconds = TimeUnit.MILLISECONDS.toSeconds(file.lastModified());

    ContentValues values = new ContentValues(11);
    values.put(ImageColumns.TITLE, title);
    values.put(ImageColumns.DISPLAY_NAME, title + JPEG_POSTFIX);
    values.put(ImageColumns.DATE_TAKEN, date);
    values.put(ImageColumns.MIME_TYPE, mimeType);
    values.put(ImageColumns.DATE_MODIFIED, dateModifiedSeconds);
    // Clockwise rotation in degrees. 0, 90, 180, or 270.
    values.put(ImageColumns.ORIENTATION, orientation);
    values.put(ImageColumns.DATA, path);
    values.put(ImageColumns.SIZE, jpegLength);

    setImageSize(values, width, height);

    if (location != null)
    {
        values.put(ImageColumns.LATITUDE, location.getLatitude());
        values.put(ImageColumns.LONGITUDE, location.getLongitude());
    }
    return values;
}
 
Example #18
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
protected long getImageForPathCleared(String path) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                ImagesBucketThumbnailQuery.PROJECTION, ImageColumns.DATA + "= ? ",
                new String[] { path.replaceAll("'", "''") }, ImageColumns.DATE_MODIFIED + " DESC");
        if (cursor.moveToFirst()) {
            return cursor.getLong(ImagesBucketThumbnailQuery._ID);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    throw new FileNotFoundException("No image found for bucket");
}
 
Example #19
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor queryRecentDocuments(String rootId, String[] projection)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(rootId)) {
            // include all unique buckets
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImageQuery.PROJECTION, null, null, ImageColumns.DATE_MODIFIED + " DESC");
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext() && result.getCount() < 64) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(rootId)) {
            // include all unique buckets
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideoQuery.PROJECTION, null, null, VideoColumns.DATE_MODIFIED + " DESC");
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext() && result.getCount() < 64) {
                includeVideo(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported root " + rootId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example #20
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
protected long getImageForBucketCleared(long bucketId) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                ImagesBucketThumbnailQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + bucketId,
                null, ImageColumns.DATE_MODIFIED + " DESC");
        if (cursor.moveToFirst()) {
            return cursor.getLong(ImagesBucketThumbnailQuery._ID);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    throw new FileNotFoundException("No video found for bucket");
}
 
Example #21
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
protected long getImageForPathCleared(String path) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                ImagesBucketThumbnailQuery.PROJECTION, ImageColumns.DATA + "= ? ",
                new String[] { path.replaceAll("'", "''") }, ImageColumns.DATE_MODIFIED + " DESC");
        if (cursor.moveToFirst()) {
            return cursor.getLong(ImagesBucketThumbnailQuery._ID);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    throw new FileNotFoundException("No image found for bucket");
}
 
Example #22
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor queryRecentDocuments(String rootId, String[] projection)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(rootId)) {
            // include all unique buckets
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImageQuery.PROJECTION, null, null, ImageColumns.DATE_MODIFIED + " DESC");
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext() && result.getCount() < 64) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(rootId)) {
            // include all unique buckets
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideoQuery.PROJECTION, null, null, VideoColumns.DATE_MODIFIED + " DESC");
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext() && result.getCount() < 64) {
                includeVideo(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported root " + rootId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example #23
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
protected long getImageForBucketCleared(long bucketId) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                ImagesBucketThumbnailQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + bucketId,
                null, ImageColumns.DATE_MODIFIED + " DESC");
        if (cursor.moveToFirst()) {
            return cursor.getLong(ImagesBucketThumbnailQuery._ID);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    throw new FileNotFoundException("No video found for bucket");
}
 
Example #24
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
protected long getImageForPathCleared(String path) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                ImagesBucketThumbnailQuery.PROJECTION, ImageColumns.DATA + "= ? ",
                new String[] { path.replaceAll("'", "''") }, ImageColumns.DATE_MODIFIED + " DESC");
        if (cursor.moveToFirst()) {
            return cursor.getLong(ImagesBucketThumbnailQuery._ID);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    throw new FileNotFoundException("No image found for bucket");
}
 
Example #25
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor queryRecentDocuments(String rootId, String[] projection)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(rootId)) {
            // include all unique buckets
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImageQuery.PROJECTION, null, null, ImageColumns.DATE_MODIFIED + " DESC");
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext() && result.getCount() < 64) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(rootId)) {
            // include all unique buckets
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideoQuery.PROJECTION, null, null, VideoColumns.DATE_MODIFIED + " DESC");
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext() && result.getCount() < 64) {
                includeVideo(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported root " + rootId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example #26
Source File: LocalAlbum.java    From medialibrary with Apache License 2.0 5 votes vote down vote up
public LocalAlbum(Path path, MediaDataContext application, int bucketId,
                  boolean isImage, String name) {
    super(path, nextVersionNumber());
    mApplication = application;
    mResolver = application.getContentResolver();
    mBucketId = bucketId;
    mName = name;
    mIsImage = isImage;

    if (isImage) {
        mWhereClause = ImageColumns.BUCKET_ID + " = ?";
        mOrderClause = ImageColumns.DATE_TAKEN + " DESC, "
                + ImageColumns._ID + " DESC";
        mBaseUri = Images.Media.EXTERNAL_CONTENT_URI;
        mProjection = LocalImage.PROJECTION;
        mItemPath = LocalImage.ITEM_PATH;
    } else {
        mWhereClause = VideoColumns.BUCKET_ID + " = ?";
        mOrderClause = VideoColumns.DATE_TAKEN + " DESC, "
                + VideoColumns._ID + " DESC";
        mBaseUri = Video.Media.EXTERNAL_CONTENT_URI;
        mProjection = LocalVideo.PROJECTION;
        mItemPath = LocalVideo.ITEM_PATH;
    }

    mNotifier = new ChangeNotifier(this, mBaseUri, application);
}
 
Example #27
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(ident.type)) {
            // single root
            includeImagesRootDocument(result);
        } else if (TYPE_IMAGES_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImagesBucketQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + ident.id,
                    null, ImagesBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImagesBucket(result, cursor);
            }
        } else if (TYPE_IMAGE.equals(ident.type)) {
            // single image
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImageQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(ident.type)) {
            // single root
            includeVideosRootDocument(result);
        } else if (TYPE_VIDEOS_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideosBucketQuery.PROJECTION, VideoColumns.BUCKET_ID + "=" + ident.id,
                    null, VideosBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideosBucket(result, cursor);
            }
        } else if (TYPE_VIDEO.equals(ident.type)) {
            // single video
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideoQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideo(result, cursor);
            }
        } else if (TYPE_AUDIO_ROOT.equals(ident.type)) {
            // single root
            includeAudioRootDocument(result);
        } else if (TYPE_ARTIST.equals(ident.type)) {
            // single artist
            cursor = resolver.query(Artists.EXTERNAL_CONTENT_URI,
                    ArtistQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Artists.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeArtist(result, cursor);
            }
        } else if (TYPE_ALBUM.equals(ident.type)) {
            // single album
            cursor = resolver.query(Albums.EXTERNAL_CONTENT_URI,
                    AlbumQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Albums.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAlbum(result, cursor);
            }
        } else if (TYPE_AUDIO.equals(ident.type)) {
            // single song
            cursor = resolver.query(Audio.Media.EXTERNAL_CONTENT_URI,
                    SongQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Audio.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAudio(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example #28
Source File: ImagePickerUtils.java    From umeng_community_android with MIT License 4 votes vote down vote up
public static String query(Context context, Uri uri) {
	Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null, null);
	cursor.moveToNext();
	return cursor.getString(cursor.getColumnIndex(ImageColumns.DATA));
}
 
Example #29
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(ident.type)) {
            // single root
            includeImagesRootDocument(result);
        } else if (TYPE_IMAGES_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImagesBucketQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + ident.id,
                    null, ImagesBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImagesBucket(result, cursor);
            }
        } else if (TYPE_IMAGE.equals(ident.type)) {
            // single image
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImageQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(ident.type)) {
            // single root
            includeVideosRootDocument(result);
        } else if (TYPE_VIDEOS_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideosBucketQuery.PROJECTION, VideoColumns.BUCKET_ID + "=" + ident.id,
                    null, VideosBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideosBucket(result, cursor);
            }
        } else if (TYPE_VIDEO.equals(ident.type)) {
            // single video
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideoQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideo(result, cursor);
            }
        } else if (TYPE_AUDIO_ROOT.equals(ident.type)) {
            // single root
            includeAudioRootDocument(result);
        } else if (TYPE_ARTIST.equals(ident.type)) {
            // single artist
            cursor = resolver.query(Artists.EXTERNAL_CONTENT_URI,
                    ArtistQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Artists.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeArtist(result, cursor);
            }
        } else if (TYPE_ALBUM.equals(ident.type)) {
            // single album
            cursor = resolver.query(Albums.EXTERNAL_CONTENT_URI,
                    AlbumQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Albums.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAlbum(result, cursor);
            }
        } else if (TYPE_AUDIO.equals(ident.type)) {
            // single song
            cursor = resolver.query(Audio.Media.EXTERNAL_CONTENT_URI,
                    SongQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Audio.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAudio(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example #30
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(ident.type)) {
            // single root
            includeImagesRootDocument(result);
        } else if (TYPE_IMAGES_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImagesBucketQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + ident.id,
                    null, ImagesBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImagesBucket(result, cursor);
            }
        } else if (TYPE_IMAGE.equals(ident.type)) {
            // single image
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImageQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(ident.type)) {
            // single root
            includeVideosRootDocument(result);
        } else if (TYPE_VIDEOS_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideosBucketQuery.PROJECTION, VideoColumns.BUCKET_ID + "=" + ident.id,
                    null, VideosBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideosBucket(result, cursor);
            }
        } else if (TYPE_VIDEO.equals(ident.type)) {
            // single video
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideoQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideo(result, cursor);
            }
        } else if (TYPE_AUDIO_ROOT.equals(ident.type)) {
            // single root
            includeAudioRootDocument(result);
        } else if (TYPE_ARTIST.equals(ident.type)) {
            // single artist
            cursor = resolver.query(Artists.EXTERNAL_CONTENT_URI,
                    ArtistQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Artists.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeArtist(result, cursor);
            }
        } else if (TYPE_ALBUM.equals(ident.type)) {
            // single album
            cursor = resolver.query(Albums.EXTERNAL_CONTENT_URI,
                    AlbumQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Albums.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAlbum(result, cursor);
            }
        } else if (TYPE_AUDIO.equals(ident.type)) {
            // single song
            cursor = resolver.query(Audio.Media.EXTERNAL_CONTENT_URI,
                    SongQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Audio.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAudio(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}