コード例 #1
0
 /**
  * 获得照片的绝对路径
  *
  * @param uri 拍照或者选取照片返回的数据
  * @return 返回字符串
  */
 private String getImagePath(final Uri uri) {
   String[] projection = {MediaStore.Images.Media.DATA};
   Cursor cursor = MediaStore.Images.Media.query(getContentResolver(), uri, projection);
   cursor.moveToFirst();
   String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
   cursor.close();
   return path;
 }
コード例 #2
0
  public static String getPathOfPhotoByUri(Context context, Uri uri) {
    String[] filePathColumn = {MediaStore.Images.Media.DATA};

    Cursor cursor =
        MediaStore.Images.Media.query(context.getContentResolver(), uri, filePathColumn);
    cursor.moveToFirst();

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String picturePath = cursor.getString(columnIndex);
    cursor.close();
    return picturePath;
  }
コード例 #3
0
  private String getRealPathFromUri(Uri contentUri) {
    String path = null;
    String scheme = contentUri.getScheme();

    if (scheme.equals("content")) {
      String[] proj = {MediaStore.Images.Media.DATA};
      Cursor cursor =
          MediaStore.Images.Media.query(getContentResolver(), contentUri, proj, null, null, null);
      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

      if (cursor != null) {
        if (cursor.moveToFirst() == true) path = cursor.getString(column_index);
        cursor.close();
      }

      cursor = null;
    } else if (scheme.equals("file")) path = contentUri.getPath();

    return path;
  }
コード例 #4
0
 protected Bitmap getThumbnailOfLastPhoto() {
   Cursor cursor =
       MediaStore.Images.Media.query(
           getContentResolver(),
           MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
           new String[] {
             MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATE_TAKEN
           },
           null,
           null,
           MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC LIMIT 1");
   Bitmap thumb = null;
   if (cursor.moveToNext()) {
     int id = cursor.getInt(0);
     thumb =
         MediaStore.Images.Thumbnails.getThumbnail(
             getContentResolver(), id, MediaStore.Images.Thumbnails.MINI_KIND, null);
   }
   cursor.close();
   return thumb;
 }
コード例 #5
0
ファイル: PhotosPresence.java プロジェクト: raenoh/dungbeetle
    private Uri getLatestCameraPhoto() {
      String selection = ImageColumns.BUCKET_DISPLAY_NAME + " = 'Camera'";
      String[] selectionArgs = null;
      String sort = ImageColumns._ID + " DESC LIMIT 1";
      Cursor c =
          android.provider.MediaStore.Images.Media.query(
              mmContext.getContentResolver(),
              Images.Media.EXTERNAL_CONTENT_URI,
              new String[] {ImageColumns._ID},
              selection,
              selectionArgs,
              sort);
      try {

        int idx = c.getColumnIndex(ImageColumns._ID);
        if (c.moveToFirst()) {
          return Uri.withAppendedPath(Images.Media.EXTERNAL_CONTENT_URI, c.getString(idx));
        }
        return null;
      } finally {
        c.close();
      }
    }