android.provider.MediaStore.Images.Media Java Examples
The following examples show how to use
android.provider.MediaStore.Images.Media.
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: PhotoDirectoryLoader.java From PhotoPicker with Apache License 2.0 | 7 votes |
public PhotoDirectoryLoader(Context context, boolean showGif) { super(context); setProjection(IMAGE_PROJECTION); setUri(Media.EXTERNAL_CONTENT_URI); setSortOrder(Media.DATE_ADDED + " DESC"); setSelection( MIME_TYPE + "=? or " + MIME_TYPE + "=? or "+ MIME_TYPE + "=? " + (showGif ? ("or " + MIME_TYPE + "=?") : "")); String[] selectionArgs; if (showGif) { selectionArgs = new String[] { "image/jpeg", "image/png", "image/jpg","image/gif" }; } else { selectionArgs = new String[] { "image/jpeg", "image/png", "image/jpg" }; } setSelectionArgs(selectionArgs); }
Example #2
Source File: PhotoDirectoryLoader.java From PhotoPicker with Apache License 2.0 | 6 votes |
public PhotoDirectoryLoader(Context context, boolean showGif) { super(context); setProjection(IMAGE_PROJECTION); setUri(Media.EXTERNAL_CONTENT_URI); setSortOrder(Media.DATE_ADDED + " DESC"); setSelection( MIME_TYPE + "=? or " + MIME_TYPE + "=? or "+ MIME_TYPE + "=? " + (showGif ? ("or " + MIME_TYPE + "=?") : "")); String[] selectionArgs; if (showGif) { selectionArgs = new String[] { "image/jpeg", "image/png", "image/jpg","image/gif" }; } else { selectionArgs = new String[] { "image/jpeg", "image/png", "image/jpg" }; } setSelectionArgs(selectionArgs); }
Example #3
Source File: PhotoDirectoryLoader.java From PhotoPicker with Apache License 2.0 | 6 votes |
public PhotoDirectoryLoader(Context context, boolean showGif) { super(context); setProjection(IMAGE_PROJECTION); setUri(Media.EXTERNAL_CONTENT_URI); setSortOrder(Media.DATE_ADDED + " DESC"); setSelection( MIME_TYPE + "=? or " + MIME_TYPE + "=? or "+ MIME_TYPE + "=? " + (showGif ? ("or " + MIME_TYPE + "=?") : "")); String[] selectionArgs; if (showGif) { selectionArgs = new String[] { "image/jpeg", "image/png", "image/jpg","image/gif" }; } else { selectionArgs = new String[] { "image/jpeg", "image/png", "image/jpg" }; } setSelectionArgs(selectionArgs); }
Example #4
Source File: Utils.java From android-utils with MIT License | 6 votes |
@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 #5
Source File: Utils.java From android-utils with MIT License | 6 votes |
@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 #6
Source File: ImageUtils.java From android-utils with MIT License | 6 votes |
/** * Scales the image independently of the screen density of the device. Maintains image aspect * ratio. * * @param uri Uri of the source bitmap **/ public static Uri scaleDownBitmapForUri(Context ctx, Uri uri, int newHeight) throws FileNotFoundException, IOException { if (uri == null) throw new NullPointerException(ERROR_URI_NULL); if (!MediaUtils.isMediaContentUri(uri)) return null; Bitmap original = Media.getBitmap(ctx.getContentResolver(), uri); Bitmap bmp = scaleBitmap(ctx, original, newHeight); Uri destUri = null; String uriStr = Utils.writeImageToMedia(ctx, bmp, "", ""); if (uriStr != null) { destUri = Uri.parse(uriStr); } return destUri; }
Example #7
Source File: AlbumController.java From umeng_community_android with MIT License | 6 votes |
/** * 获取某个相册中的所有图片 * * @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: AlbumController.java From umeng_community_android with MIT License | 6 votes |
/** * 获取最近使用的照片 * * @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 #9
Source File: GooglePlayReceiverTest.java From firebase-jobdispatcher-android with Apache License 2.0 | 6 votes |
@Test public void prepareJob() { Intent intent = new Intent(); Bundle encode = encodeContentUriJob(getContentUriTrigger(), TestUtil.JOB_CODER); intent.putExtra(GooglePlayJobWriter.REQUEST_PARAM_EXTRAS, encode); Parcel container = Parcel.obtain(); container.writeStrongBinder(new Binder()); PendingCallback pcb = new PendingCallback(container); intent.putExtra("callback", pcb); ArrayList<Uri> uris = new ArrayList<>(); uris.add(ContactsContract.AUTHORITY_URI); uris.add(Media.EXTERNAL_CONTENT_URI); intent.putParcelableArrayListExtra(BundleProtocol.PACKED_PARAM_TRIGGERED_URIS, uris); JobInvocation jobInvocation = receiver.prepareJob(intent); assertEquals(jobInvocation.getTriggerReason().getTriggeredContentUris(), uris); }
Example #10
Source File: JobCoderTest.java From firebase-jobdispatcher-android with Apache License 2.0 | 6 votes |
@Test public void decodeIntentBundle() { Bundle bundle = new Bundle(); ContentUriTrigger uriTrigger = getContentUriTrigger(); Bundle encode = encodeContentUriJob(uriTrigger, coder); bundle.putBundle(GooglePlayJobWriter.REQUEST_PARAM_EXTRAS, encode); ArrayList<Uri> uris = new ArrayList<>(); uris.add(ContactsContract.AUTHORITY_URI); uris.add(Media.EXTERNAL_CONTENT_URI); bundle.putParcelableArrayList(BundleProtocol.PACKED_PARAM_TRIGGERED_URIS, uris); JobInvocation jobInvocation = coder.decodeIntentBundle(bundle); assertEquals(uris, jobInvocation.getTriggerReason().getTriggeredContentUris()); assertEquals("TAG", jobInvocation.getTag()); assertEquals(uriTrigger.getUris(), ((ContentUriTrigger) jobInvocation.getTrigger()).getUris()); assertEquals(TestJobService.class.getName(), jobInvocation.getService()); assertEquals( RetryStrategy.DEFAULT_EXPONENTIAL.getPolicy(), jobInvocation.getRetryStrategy().getPolicy()); }
Example #11
Source File: PhotoDirectoryLoader.java From ObservableScheduler with Apache License 2.0 | 6 votes |
public PhotoDirectoryLoader(Context context, boolean showGif) { super(context); setProjection(IMAGE_PROJECTION); setUri(Media.EXTERNAL_CONTENT_URI); setSortOrder(Media.DATE_ADDED + " DESC"); setSelection( MIME_TYPE + "=? or " + MIME_TYPE + "=? " + (showGif ? ("or " + MIME_TYPE + "=?") : "")); String[] selectionArgs; if (showGif) { selectionArgs = new String[] { "image/jpeg", "image/png", "image/gif" }; } else { selectionArgs = new String[] { "image/jpeg", "image/png" }; } setSelectionArgs(selectionArgs); }
Example #12
Source File: AlbumTask.java From boxing with Apache License 2.0 | 6 votes |
private void buildAlbumInfo(ContentResolver cr) { String[] distinctBucketColumns = new String[]{Media.BUCKET_ID, Media.BUCKET_DISPLAY_NAME}; Cursor bucketCursor = null; try { bucketCursor = cr.query(Media.EXTERNAL_CONTENT_URI, distinctBucketColumns, "0==0)" + " GROUP BY(" + Media.BUCKET_ID, null, Media.DATE_MODIFIED + " desc"); if (bucketCursor != null && bucketCursor.moveToFirst()) { do { String buckId = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_ID)); String name = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_DISPLAY_NAME)); AlbumEntity album = buildAlbumInfo(name, buckId); if (!TextUtils.isEmpty(buckId)) { buildAlbumCover(cr, buckId, album); } } while (bucketCursor.moveToNext()); } } finally { if (bucketCursor != null) { bucketCursor.close(); } } }
Example #13
Source File: QrCodeShareActivity.java From letv with Apache License 2.0 | 6 votes |
public void onClick(View v) { int id = v.getId(); if (R.id.btn_share == id) { this.mIvQrCodeArea.setDrawingCacheEnabled(true); PageJumpUtil.jumpToPageSystemShare(this, "", "", "", Uri.parse(Media.insertImage(getContentResolver(), this.mIvQrCodeArea.getDrawingCache(), null, null))); } else if (R.id.btn_refresh == id) { DialogUtil.showDialog(this, getResources().getString(R.string.qrcode_gen_refresh_prompt), "", "", null, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); QrCodeShareActivity.this.refreshQrCode(); } }); } else if (R.id.common_nav_left == id) { finish(); } }
Example #14
Source File: Utils.java From android-utils with MIT License | 5 votes |
/** * Inserts an image into {@link android.provider.MediaStore.Images.Media} content provider of the device. * * @return The media content Uri to the newly created image, or null if the image failed to be * stored for any reason. **/ public static String writeImageToMedia(Context ctx, Bitmap image, String title, String description) { // TODO: move to MediaUtils if (ctx == null) { throw new NullPointerException("Context cannot be null"); } return Media.insertImage(ctx.getContentResolver(), image, title, description); }
Example #15
Source File: ScreenShotListenManager.java From ShareSDK-for-Android with MIT License | 5 votes |
public void startListen() { assertInMainThread(); this.sHasCallbackPaths.clear(); this.startListenTime = System.currentTimeMillis(); this.internalObserver = new MediaContentObserver(Media.INTERNAL_CONTENT_URI, this.uiHandler); this.externalObserver = new MediaContentObserver(Media.EXTERNAL_CONTENT_URI, this.uiHandler); this.context.getContentResolver().registerContentObserver(Media.INTERNAL_CONTENT_URI, false, this.internalObserver); this.context.getContentResolver().registerContentObserver(Media.EXTERNAL_CONTENT_URI, false, this.externalObserver); }
Example #16
Source File: UEImageManager.java From Auie with GNU General Public License v2.0 | 5 votes |
/** * 获取图片原始路径 */ public String getOriginalImagePath(String id) { Cursor cursor = mContentResolver.query(Media.EXTERNAL_CONTENT_URI, IMAGES_PROJECTTION, Media._ID + "=" + id, null, null); if (cursor != null) { cursor.moveToFirst(); return cursor.getString(cursor.getColumnIndex(Media.DATA)); } return null; }
Example #17
Source File: UEImageManager.java From Auie with GNU General Public License v2.0 | 5 votes |
/** * 创建相册集合 */ private void createBuckets(){ createThumbnails(); Cursor cursor = mContentResolver.query(Media.EXTERNAL_CONTENT_URI, BOCKETS_PROJECTION, null, null, null); if (cursor.moveToFirst()) { int idIndex = cursor.getColumnIndex(Media._ID); int dataIndex = cursor.getColumnIndex(Media.DATA); int bucketDisplatNameIndex = cursor.getColumnIndex(Media.BUCKET_DISPLAY_NAME); int bucketIdIndex = cursor.getColumnIndex(Media.BUCKET_ID); buckets.clear(); tempbuckets.clear(); do { String id = cursor.getString(idIndex); String data = cursor.getString(dataIndex); String bucketDisplayName = cursor.getString(bucketDisplatNameIndex); String bucketId = cursor.getString(bucketIdIndex); Bucket bucket = buckets.get(bucketId); if (bucket == null) { bucket = new Bucket(); bucket.name = bucketDisplayName; buckets.put(bucketId, bucket); tempbuckets.add(bucket); } Image image = new Image(); image.id = id; image.path = data; image.thumbnail = thumbnails.get(id); bucket.add(image); } while (cursor.moveToNext()); hasCreatedBuckets = true; } cursor.close(); }
Example #18
Source File: UEImageManager.java From Auie with GNU General Public License v2.0 | 5 votes |
/** * 创建图片原图集合 */ private void createAlbums(){ Cursor cursor = mContentResolver.query(Media.EXTERNAL_CONTENT_URI, ALBUMS_PROJECTION, null, null, null); if (cursor.moveToFirst()) { int idIndex = cursor.getColumnIndex(Albums._ID); int albumIndex = cursor.getColumnIndex(Albums.ALBUM); int albumArtIndex = cursor.getColumnIndex(Albums.ALBUM_ART); int albumKeyIndex = cursor.getColumnIndex(Albums.ALBUM_KEY); int artistIndex = cursor.getColumnIndex(Albums.ARTIST); int numberOfSongsIndex = cursor.getColumnIndex(Albums.NUMBER_OF_SONGS); do { int id = cursor.getInt(idIndex); int numberOfSongs = cursor.getInt(numberOfSongsIndex); String album = cursor.getString(albumIndex); String artist = cursor.getString(artistIndex); String albumKey = cursor.getString(albumKeyIndex); String albumArt = cursor.getString(albumArtIndex); Map<String, String> albumItem = new HashMap<String, String>(); albumItem.put("_id", String.valueOf(id)); albumItem.put("album", album); albumItem.put("albumArt", albumArt); albumItem.put("albumKey", albumKey); albumItem.put("artist", artist); albumItem.put("numOfSongs", String.valueOf(numberOfSongs)); albums.add(albumItem); } while (cursor.moveToNext()); } cursor.close(); }
Example #19
Source File: AlbumHelper.java From UltimateAndroid with Apache License 2.0 | 5 votes |
/** * 得到原始图像路径 * * @param image_id * @return */ String getOriginalImagePath(String image_id) { String path = null; Log.i(TAG, "---(^o^)----" + image_id); String[] projection = { Media._ID, Media.DATA }; Cursor cursor = cr.query(Media.EXTERNAL_CONTENT_URI, projection, Media._ID + "=" + image_id, null, null); if (cursor != null) { cursor.moveToFirst(); path = cursor.getString(cursor.getColumnIndex(Media.DATA)); } return path; }
Example #20
Source File: AlbumHelper.java From school_shop with MIT License | 5 votes |
String getOriginalImagePath(String image_id) { String path = null; Log.i(TAG, "---(^o^)----" + image_id); String[] projection = { Media._ID, Media.DATA }; Cursor cursor = cr.query(Media.EXTERNAL_CONTENT_URI, projection, Media._ID + "=" + image_id, null, null); if (cursor != null) { cursor.moveToFirst(); path = cursor.getString(cursor.getColumnIndex(Media.DATA)); } return path; }
Example #21
Source File: AlbumHelper.java From quickmark with MIT License | 5 votes |
/** * �õ�ԭʼͼ��·�� * * @param image_id * @return */ String getOriginalImagePath(String image_id) { String path = null; Log.i(TAG, "---(^o^)----" + image_id); String[] projection = { Media._ID, Media.DATA }; Cursor cursor = cr.query(Media.EXTERNAL_CONTENT_URI, projection, Media._ID + "=" + image_id, null, null); if (cursor != null) { cursor.moveToFirst(); path = cursor.getString(cursor.getColumnIndex(Media.DATA)); } return path; }
Example #22
Source File: StorageManager.java From ground-android with Apache License 2.0 | 5 votes |
/** Observe for the result of request code {@link StorageManager#PICK_PHOTO_REQUEST_CODE}. */ public Observable<Bitmap> photoPickerResult() { return activityStreams .getNextActivityResult(PICK_PHOTO_REQUEST_CODE) .flatMap(this::onPickPhotoResult) .map(uri -> Media.getBitmap(context.getContentResolver(), uri)); }
Example #23
Source File: FeedBackImageView.java From letv with Apache License 2.0 | 5 votes |
public void setUri(Uri uri) { if (uri != null) { this.mUri = uri; this.mPath = getPath(this.mContext, this.mUri); this.mFile = new File(this.mPath); String name = this.mFile.getName(); name = name.substring(0, name.indexOf(".")); Bitmap bitmap = null; if (this.mFile.length() > 262144) { try { bitmap = compressImage(FileUtils.getBitmapByPath(this.mPath, 1800, 1800)); } catch (FileNotFoundException e) { e.printStackTrace(); } try { this.mFile = File.createTempFile(name, ".jpg"); bitmap.compress(CompressFormat.JPEG, 100, new FileOutputStream(this.mFile)); } catch (IOException e2) { e2.printStackTrace(); } } else { try { bitmap = Media.getBitmap(this.mContext.getContentResolver(), this.mUri); } catch (IOException e22) { e22.printStackTrace(); } } setImageBitmap(bitmap); } }
Example #24
Source File: Utils.java From android-utils with MIT License | 5 votes |
/** * @param mediaUri uri to the media resource. For e.g. content://media/external/images/media/45490 or * content://media/external/video/media/45490 * @return Size in bytes * @deprecated Use {@link MediaUtils#getMediaSize(Context, Uri)} * Gets the size of the media resource pointed to by the paramter mediaUri. * <p/> * Known bug: for unknown reason, the image size for some images was found to be 0 **/ public static long getMediaSize(Context context, Uri mediaUri) { Cursor cur = context.getContentResolver().query(mediaUri, new String[]{Media.SIZE}, null, null, null); long size = -1; try { if (cur != null && cur.getCount() > 0) { while (cur.moveToNext()) { size = cur.getLong(cur.getColumnIndex(Media.SIZE)); // for unknown reason, the image size for image was found to // be 0 // Log.v( TAG, "#getSize byte.size: " + size ); if (size == 0) Log.w(TAG, "#getSize The media size was found to be 0. Reason: UNKNOWN"); } // end while } else if (cur.getCount() == 0) { Log.e(TAG, "#getMediaSize cur size is 0. File may not exist"); } else { Log.e(TAG, "#getMediaSize cur is null"); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } return size; }
Example #25
Source File: ImagePickerHelper.java From SimplifyReader with Apache License 2.0 | 5 votes |
private void buildImagesBucketList() { getThumbnail(); mBucketList.clear(); String columns[] = new String[] { Media._ID, Media.BUCKET_ID, Media.PICASA_ID, Media.DATA, Media.DISPLAY_NAME, Media.TITLE, Media.SIZE, Media.BUCKET_DISPLAY_NAME }; Cursor cursor = contentResolver.query(Media.EXTERNAL_CONTENT_URI, columns, null, null, null); if (cursor.moveToFirst()) { int photoIDIndex = cursor.getColumnIndexOrThrow(Media._ID); int photoPathIndex = cursor.getColumnIndexOrThrow(Media.DATA); int bucketDisplayNameIndex = cursor.getColumnIndexOrThrow(Media.BUCKET_DISPLAY_NAME); int bucketIdIndex = cursor.getColumnIndexOrThrow(Media.BUCKET_ID); do { String _id = cursor.getString(photoIDIndex); String path = cursor.getString(photoPathIndex); String bucketName = cursor.getString(bucketDisplayNameIndex); String bucketId = cursor.getString(bucketIdIndex); ImageBucket bucket = mBucketList.get(bucketId); if (bucket == null) { bucket = new ImageBucket(); mBucketList.put(bucketId, bucket); bucket.bucketList = new ArrayList<ImageItem>(); bucket.bucketName = bucketName; } bucket.count++; ImageItem imageItem = new ImageItem(); imageItem.setImageId(_id); imageItem.setImagePath(path); imageItem.setThumbnailPath(mThumbnailList.get(_id)); bucket.bucketList.add(imageItem); } while (cursor.moveToNext()); } hasBuildImagesBucketList = true; }
Example #26
Source File: AlbumController.java From umeng_community_android with MIT License | 5 votes |
/** * 获取所有相册 * * @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 #27
Source File: AlbumTask.java From boxing with Apache License 2.0 | 5 votes |
/** * get the cover and count * * @param buckId album id */ private void buildAlbumCover(ContentResolver cr, String buckId, AlbumEntity album) { String[] photoColumn = new String[]{Media._ID, Media.DATA}; boolean isNeedGif = mPickerConfig != null && mPickerConfig.isNeedGif(); String selectionId = isNeedGif ? SELECTION_ID : SELECTION_ID_WITHOUT_GIF; String[] args = isNeedGif ? SELECTION_ARGS_IMAGE_MIME_TYPE : SELECTION_ARGS_IMAGE_MIME_TYPE_WITHOUT_GIF; String[] selectionArgs = new String[args.length + 1]; selectionArgs[0] = buckId; for (int i = 1; i < selectionArgs.length; i++) { selectionArgs[i] = args[i-1]; } Cursor coverCursor = cr.query(Media.EXTERNAL_CONTENT_URI, photoColumn, selectionId, selectionArgs, Media.DATE_MODIFIED + " desc"); try { if (coverCursor != null && coverCursor.moveToFirst()) { String picPath = coverCursor.getString(coverCursor.getColumnIndex(Media.DATA)); String id = coverCursor.getString(coverCursor.getColumnIndex(Media._ID)); album.mCount = coverCursor.getCount(); album.mImageList.add(new ImageMedia(id, picPath)); if (album.mImageList.size() > 0) { mBucketMap.put(buckId, album); } } } finally { if (coverCursor != null) { coverCursor.close(); } } }
Example #28
Source File: ImageList.java From droidddle with Apache License 2.0 | 5 votes |
public HashMap<String, String> getBucketIds() { Uri uri = mBaseUri.buildUpon().appendQueryParameter("distinct", "true").build(); Cursor cursor = Media.query(mContentResolver, uri, new String[]{Media.BUCKET_DISPLAY_NAME, Media.BUCKET_ID}, whereClause(), whereClauseArgs(), null); try { HashMap<String, String> hash = new HashMap<String, String>(); while (cursor.moveToNext()) { hash.put(cursor.getString(1), cursor.getString(0)); } return hash; } finally { cursor.close(); } }
Example #29
Source File: HomeActivity.java From photo-editor with MIT License | 4 votes |
private void dispatchGalleryIntent() { Intent galleryIntent = new Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI); startActivityForResult(galleryIntent, GALLERY_RESULT); }
Example #30
Source File: ImageUtils.java From android-utils with MIT License | 4 votes |
/** * Rotate the image at the specified uri. For the rotation of the image the * {@link android.media.ExifInterface} data in the image will be used. * * @param uri Uri of the image to be rotated. **/ public static Uri rotateImage(Context context, Uri uri) throws FileNotFoundException, IOException { // rotate the image if (uri == null) { throw new NullPointerException(ERROR_URI_NULL); } if (!MediaUtils.isMediaContentUri(uri)) { return null; } int invalidOrientation = -1; byte[] data = Utils.getMediaData(context, uri); int orientation = getOrientation(context, uri); Uri newUri = null; try { Log.d(TAG, "#rotateImage Exif orientation: " + orientation); if (orientation != invalidOrientation) { Matrix matrix = new Matrix(); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: matrix.postRotate(90); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.postRotate(180); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.postRotate(270); break; } // set some options so the memory is manager properly BitmapFactory.Options options = new BitmapFactory.Options(); // options.inPreferredConfig = Bitmap.Config.RGB_565; // try to enable this if // OutOfMem issue still persists options.inPurgeable = true; options.inInputShareable = true; Bitmap original = BitmapFactory.decodeByteArray(data, 0, data.length, options); Bitmap rotatedBitmap = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), matrix, true); // rotating // bitmap String newUrl = Media.insertImage(((Activity) context).getContentResolver(), rotatedBitmap, "", ""); if (newUrl != null) { newUri = Uri.parse(newUrl); } } } catch (Exception e) { e.printStackTrace(); } return newUri; }