类android.provider.MediaStore.Images.Media源码实例Demo

下面列出了怎么用android.provider.MediaStore.Images.Media的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: PhotoPicker   文件: PhotoDirectoryLoader.java
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);
}
 
源代码2 项目: PhotoPicker   文件: PhotoDirectoryLoader.java
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);
}
 
源代码3 项目: letv   文件: QrCodeShareActivity.java
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();
    }
}
 
源代码4 项目: boxing   文件: AlbumTask.java
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();
        }
    }
}
 
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);
}
 
@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());
}
 
@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);
}
 
源代码8 项目: umeng_community_android   文件: AlbumController.java
/**
 * 获取最近使用的照片
 * 
 * @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;
}
 
源代码9 项目: umeng_community_android   文件: AlbumController.java
/**
 * 获取某个相册中的所有图片
 * 
 * @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;
}
 
源代码10 项目: android-utils   文件: ImageUtils.java
/**
 * 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;
}
 
源代码11 项目: android-utils   文件: Utils.java
@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;
}
 
源代码12 项目: android-utils   文件: Utils.java
@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;
}
 
源代码13 项目: PhotoPicker   文件: PhotoDirectoryLoader.java
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);
}
 
源代码14 项目: ground-android   文件: StorageManager.java
/** 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));
}
 
源代码15 项目: letv   文件: FeedBackImageView.java
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);
    }
}
 
源代码16 项目: boxing   文件: AlbumTask.java
/**
 * 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();
        }
    }
}
 
源代码17 项目: droidddle   文件: ImageList.java
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();
    }
}
 
源代码18 项目: umeng_community_android   文件: AlbumController.java
/**
 * 获取所有相册
 * 
 * @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;
}
 
源代码19 项目: SimplifyReader   文件: ImagePickerHelper.java
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;
}
 
源代码20 项目: android-utils   文件: Utils.java
/**
 * 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);
}
 
源代码21 项目: android-utils   文件: Utils.java
/**
 * @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;
}
 
源代码22 项目: quickmark   文件: AlbumHelper.java
/**
 * �õ�ԭʼͼ��·��
 * 
 * @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;
}
 
源代码23 项目: school_shop   文件: AlbumHelper.java
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;
}
 
源代码24 项目: UltimateAndroid   文件: AlbumHelper.java
/**
 * 得到原始图像路径
 * 
 * @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;
}
 
源代码25 项目: Auie   文件: UEImageManager.java
/**
 * 创建图片原图集合
 */
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();
}
 
源代码26 项目: Auie   文件: UEImageManager.java
/**
 * 创建相册集合
 */
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();
}
 
源代码27 项目: Auie   文件: UEImageManager.java
/**
 * 获取图片原始路径
 */
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;
}
 
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);
}
 
源代码29 项目: letv   文件: FeedBackImageView.java
@SuppressLint({"NewApi"})
public String getPath(Context context, Uri uri) {
    boolean isKitKat;
    if (VERSION.SDK_INT >= 19) {
        isKitKat = true;
    } else {
        isKitKat = false;
    }
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        String[] split;
        if (isExternalStorageDocument(uri)) {
            split = DocumentsContract.getDocumentId(uri).split(NetworkUtils.DELIMITER_COLON);
            if ("primary".equalsIgnoreCase(split[0])) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }
            return null;
        } else if (isDownloadsDocument(uri)) {
            return getDataColumn(context, ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(DocumentsContract.getDocumentId(uri)).longValue()), null, null);
        } else if (!isMediaDocument(uri)) {
            return null;
        } else {
            String type = DocumentsContract.getDocumentId(uri).split(NetworkUtils.DELIMITER_COLON)[0];
            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = Audio.Media.EXTERNAL_CONTENT_URI;
            }
            String selection = "_id=?";
            return getDataColumn(context, contentUri, "_id=?", new String[]{split[1]});
        }
    } else if (WidgetRequestParam.REQ_PARAM_COMMENT_CONTENT.equalsIgnoreCase(uri.getScheme())) {
        if (isGooglePhotosUri(uri)) {
            return uri.getLastPathSegment();
        }
        return getDataColumn(context, uri, null, null);
    } else if (IDataSource.SCHEME_FILE_TAG.equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    } else {
        return null;
    }
}
 
源代码30 项目: letv   文件: LetvBaseWebViewActivity.java
@TargetApi(19)
private String getPicPathFromUri(Uri uri) {
    boolean isKitKat;
    if (VERSION.SDK_INT >= 19) {
        isKitKat = true;
    } else {
        isKitKat = false;
    }
    if (isKitKat && DocumentsContract.isDocumentUri(this, uri)) {
        String[] split;
        if (isExternalStorageDocument(uri)) {
            split = DocumentsContract.getDocumentId(uri).split(com.letv.pp.utils.NetworkUtils.DELIMITER_COLON);
            if ("primary".equalsIgnoreCase(split[0])) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }
            return null;
        } else if (isDownloadsDocument(uri)) {
            return getDataColumn(this, ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(DocumentsContract.getDocumentId(uri)).longValue()), null, null);
        } else if (!isMediaDocument(uri)) {
            return null;
        } else {
            String type = DocumentsContract.getDocumentId(uri).split(com.letv.pp.utils.NetworkUtils.DELIMITER_COLON)[0];
            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = Audio.Media.EXTERNAL_CONTENT_URI;
            }
            String selection = "_id=?";
            return getDataColumn(this, contentUri, "_id=?", new String[]{split[1]});
        }
    } else if (WidgetRequestParam.REQ_PARAM_COMMENT_CONTENT.equalsIgnoreCase(uri.getScheme())) {
        if (isGooglePhotosUri(uri)) {
            return uri.getLastPathSegment();
        }
        return getDataColumn(this, uri, null, null);
    } else if (IDataSource.SCHEME_FILE_TAG.equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    } else {
        return null;
    }
}
 
 类所在包
 类方法
 同包方法