2

Is there a way to know the _ID of the image I add to MediaStore using MediaStore.Images.Media.insertImage()??

MediaStore.Images.Media.insertImage() returns the Uri of the image added.

I need to know the _ID, in order to query MediaStore and get all the image data, right after the image was saved in MediaStore.

Is there another way, even without the _ID, to query MediaStore and get all the data of the last image I added?

Thank you in advance.

MDP
  • 4,177
  • 21
  • 63
  • 119

1 Answers1

0

You could get information from the MediaStore like this from the URI:

public String getRealPathFromURI(Context context, Uri contentUri) {
  Cursor cursor = null;
  try { 
    String[] proj = { MediaStore.Images.Media.DATA };
    cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}

More info here: Get filename and path from URI from mediastore

And here: https://developer.android.com/reference/android/provider/MediaStore.Images.Media.html

sebastianf182
  • 9,844
  • 3
  • 34
  • 66