0

Now i am going on with the selection of multiple image and video i went through

https://github.com/voidberg/DmxMediaPicker which is exactly what i need but here i get only type,id.

Below code which is used to get the id and type from here how can i get the path of particular image or video which is selected.

 if (type == 0) {
idColumn = cur.getColumnIndex(MediaStore.Video.Media._ID);
bucketColumn = cur.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME);
dateColumn = cur.getColumnIndex(MediaStore.Video.Media.DATE_ADDED);
}

else {
idColumn = cur.getColumnIndex(MediaStore.Images.Media._ID);
bucketColumn = cur.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
dateColumn = cur.getColumnIndex(MediaStore.Images.Media.DATE_ADDED);
}

Tried a lot to customize by below but no use:

int id =cur.getInt(idColumn);

I tried to get the path of particular image or video from id but no change.

If anyone have idea about this please help to solve this issue.

Manoj
  • 3,947
  • 9
  • 46
  • 84

1 Answers1

0

Be careful here. You cannot assume that a media item necessarily corresponds to a file on the device. For example, you could be picking a Google+ image or video.

In those cases, the content of the MediaStore.Images.Media.DATA will be empty.

The correct way to do this is not to think about files, but rather about Uris and streams. In particular, from a media item's Uri, you can obtain an InputStream with its content by using a ContentResolver.

Take a look at this example (taken from this answer, for images):

InputStream inputStream = null;
if (ContentResolver.SCHEME_CONTENT.equals(mediaUri.getScheme())) {
    inputStream = context.getContentResolver().openInputStream(mediaUri);
} else if (ContentResolver.SCHEME_FILE.equals(mediaUri.getScheme())) {
    inputStream = new FileInputStream(mediaUri.getPath());
}

Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
Community
  • 1
  • 1
matiash
  • 54,791
  • 16
  • 125
  • 154